I'd like to get this to redirect to welcome/stats/3 asuming site_id is 3
function add_keyword()
{
$data = array(
'keyword' => $this->input->post('keywords'),
'depth' => $this->input->post('depth'),
'site_id' => $this->input->post('site_id')
);
$site_id = $this->input->post('site_id');
$this->site_model->add_keyword($data);
redirect('welcome/stats/', $site_id);
}
You have to concatenate $site_id, not pass it as a second parameter:
redirect('welcome/stats/' . $site_id);
Related
This should be like this
ID|access1|access2|access3|
and values:
1|1|0|1
//myController
$basic_data = array();
$select_access1 = $_POST("select_access1");
$select_access2 = $_POST("select_access2");
$select_access3 = $_POST("select_access3");
$select_access4 = $_POST("select_access4");
$select_access5 = $_POST("select_access5");
$basic_data[] = array('accs_trans_sec'=>$select_access1,'accs_acctng_sec'=>$select_access2, 'accs_admin_sec'=>$select_access3,'accs_dashboard_sec'=> $select_access4, 'accs_reports_sec'=>$select_access5);
$this->RoleModel->saveRole($basic_data);
//myModel
public function saveRole($basic_data)
{
foreach($basic_data as $value) {
$this->db->insert('roles_global_access', $basic_data);
}}
You can set that data to array just like this:
$data = array(
'column1' => 'My Value 1',
'column2' => 'My Value 2',
'column3' => 'My Value 3'
);
$this->db->insert("table_name", $data);
Let's assume that you are getting the values of your checkbox based on your $_POST variables.
Since you've declared $basic_data as array() no need to cast it as $basic_data[].
So on your controller it should be like this:
$basic_data = array(
'accs_trans_sec'=>$select_access1,
'accs_acctng_sec'=>$select_access2,
'accs_admin_sec'=>$select_access3,
'accs_dashboard_sec'=> $select_access4,
'accs_reports_sec'=>$select_access5
);
And your model there's no need to use loop since you are inserting Object data it should look like this:
public function saveRole($basic_data)
{
$this->db->insert('roles_global_access', $basic_data);
return ($this->db->affected_rows() != 1) ? false : true;
}
so basically, if the model returns true then it successfully inserted the data.
To check if data is inserted successfully:
$result = $this->RoleModel->saveRole($basic_data);
if($result == true){
echo ("Successfully inserted!");
}else{
echo ("Problem!");
}
First, you are not getting post data in the correct way. With $_POST have to use square brackets [].
Second, Don't use foreach loop in the model
Get data in the controller like this
$basic_data = array(
'accs_trans_sec' => $_POST['select_access1'],
'accs_acctng_sec' => $_POST['select_access2'],
'accs_admin_sec' => $_POST['select_access3'],
'accs_dashboard_sec' => $_POST['select_access4'],
'accs_reports_sec' => $_POST['select_access5']
);
$this->RoleModel->saveRole($basic_data);
Model
public function saveRole($basic_data){
return $this->db->insert('roles_global_access', $basic_data);
}
You should try this.
Controller:
$this->RoleModel->saveRole($_POST);
Model:
public function saveRole($basic_data){
extract($basic_data);
$dataset = array(
'accs_trans_sec' => $basic_data['select_access1'],
'accs_acctng_sec' => $basic_data['select_access2'],
'accs_admin_sec' => $basic_data['select_access3'],
'accs_dashboard_sec' => $basic_data['select_access4'],
'accs_reports_sec' => $basic_data['select_access5']
);
$this->db->insert('roles_global_access', $dataset);
}
There is any function limiting the input data on codeigniter?
Example:
User input qty '3'.
Then, he took input for that 3 stuff. He can't input more than 3
i tried this so far. just for input that qty
public function ajax_add()
{
$this->_validate();
$data = array(
'nama_produk' => $this->input->post('nama_produk'),
'quantity' => $this->input->post('quantity'),
'tanggal' => $this->input->post('tanggal'),
);
$insert = $this->barangmasuk->save($data);
echo json_encode(array("status" => TRUE));
}
controller
i need to insert store_merchant_id from $data..but in my coding it takes only the first id..
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
$merchant_id = Merchant_model::merchant_submit($data);
$data1 = array(
'store_merchant_id'=>$merchant_id,
'store_name'=>$store_name,
'store_phone'=>$store_phone,
'store_address1'=>$store_address1,
);
$return = Merchant_model::merchant_submit1($data1);
Model
return DB::table('le_store')->insert($data1);
I guess you need to get the last inserted id and do something with that
So, i am doing the same what you did
Step 1 : Building the input
1.
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
Step 2 : Saving the Data
$Merchant = Merchant_model::create($data);
Step 3 : Getting the inserted id
return $Merchant->id;
Now the $Merchant->id will have the last inserted id, You shall return or save this to another model that you wish to do.
Update :
As you want to update the inserted id to another table, Just do this
As usual like previous
$data = array(
'merchant_firstname' => $merchant_firstname,
'merchant_lastname' => $merchant_lastname,
'merchant_password' => $merchant_password,
'merchant_email'=>$merchant_email,
);
$Merchant = Merchant_model::create($data);
Then build $data1
$data1 = array(
'store_merchant_id'=>$Merchant->id,
'store_name'=>$store_name,
'store_phone'=>$store_phone,
'store_address1'=>$store_address1,
);
Note :
store_merchant_id'=>$Merchant->id' should be like this
Then just create it
Merchant_model::create($data1);
Hope this helps you
How can i access this multi URL in laravel 4.2.
http://localhost/new/public/library/course/1/First%20Video
My code is
Route::get('library/course/{id}', function($id){
return View::make('course')->with('id',$id);
});
Route::get('library/course/{id}/{video}', function($id, $video){
$array = array('id' => '$id', 'video' => '$video');
return View::make('course')->withvideos($array);
});
You are accessing the URL correctly, and it should reach your second route.
But you have a bug in your route:
// Your code
$array = array('id' => '$id', 'video' => '$video');
You shouldn't put single quotes around your variables -- it should be:
$array = array('id' => $id, 'video' => $video);
The single quotes force PHP not to resolve the two variables, so they are simply literal strings -- not what you want here.
Also, to pass the parameters to the view, you should adjust your code to use:
return view('course', $array);
I use findAll() like this:
$l = SiteContentRelated::model()->findAll('content_1=:c', array(':c' => $id));
How I can add condition to this?
Like as LIMIT 5 or anything?
Use CDbCriteria to specify more detailed criteria:
$criteria = new CDbCriteria;
$criteria->condition = 'content_1=:c';
$criteria->limit = 5;
$criteria->params = array(':c' => $id);
$l = SiteContentRelated::model()->findAll($criteria);
or pass an array to findAll which will be converted to a CDbCriteria:
$l = SiteContentRelated::model()->findAll(array(
'condition' => 'content_1=:c',
'limit' => 5,
'params' => array(':c' => $id),
));
When you specify a LIMIT, it's a good idea to also specify ORDER BY.
For filtering based on model attributes, you can also use findAllByAttributes:
$l = SiteContentRelated::model()->findAllByAttributes(array(
'content_1' => $id,
), array(
'limit' => 5,
));