I have a string inside a view that I need to pass to a second view.
Inside view1 I have
route('admin.olt.add', $id, $resp)
where $resp is the parameter I need to pass to the second view. My route file calls the controller that returns the second view
Route::get('/olt/{id}/add', 'OLTController#config_parameters_onu')->name('olt.add');
Is there any way where I can pass this parameter without adding it to the url?
I don't know if I fully understand your issue but as I got it, you can add this variable to a session and then fetch it whenever you want in any view for instance
to add the variable to the session
session(['resp' => $resp]);
to fetch it back
session('resp')
and here is the full docs for better guidance
Hope that is what you looking for
you should use an array of more than one parameter
route('admin.olt.add', ['id'=>$id, 'resp'=>$resp]);
Related
How to pass data from controller 1 to controller 2 in codeigniter.
I have this scenario.
Controller 1 is using $id which are unique.
controller1/view/1
controller1/view/2
controller1/view/3
and I need to get those $id and pass it everytime on my controller2. So in my controller 2, I need to get the $id which is 1,2,3. I don't want to use session as it's not gonna work and I don't want to use segment also as it's giving error if last parameter is empty. Thanks a lot.
Try this on your controller, whenever your last parameter is empty its not giving an error
function view($id=NULL){
}
I do some calculations in the controller, and pass the data to my view like this.
return View::make('fend.clist', compact('detail_'));
From this view controller "fend.clist" I'd like to open another view (blade) along with the 'detail_' variable which basically has some data that I need to show there. I tried POSTing it, but I wasn't able to recieve the data completely.
How else can I pass data from one view to another view?
By using the sessions, first put:
Session::put(['name'=>'value']);
Then get:
Session::get('name');
You must nest sub-view to view and pass data to sub-view.
return View::make('fend.clist')->nest('fend.detail', compact('detail_'));
More info in docs
I have just started learning Code Igniter .
I want to know how can I pass a variable from one controller(first_cont.php) to other controller (second_cont.php) ?
Any help would be appreciated .
Thanks in Advance :)
It will depend on the circumstances. If you want to retain the data for some time, then session data would be the way to go. However, if you only need to use it once, flash data might be more appropriate.
First step would be to initialise the session library:
$this->load->library('session');
Then store the information in flash data:
$this->session->set_flashdata('item', $myVar);
Finally, in the second controller, fetch the data:
$myVar = $this->session->flashdata('item');
Obviously this would mean you'd have to either initialise the session library again from the second controller, or create your own base controller that loads the session library and have both of your controllers inherit from that one.
I think in codeigniter you can't pass variable, between two different controller. One obvious mechanism is to use session data.
Ok, here is something about MVC most will readily quote:
A Controller is for taking input, a model is for your logic, and, a view is for displaying.
Now, strictly speaking you shouldn't want to send data from a controller to another. I can't think of any cases where that is required.
But, if it is absolutely needed, then you could simply use redirect to just redirect to the other controller.
Something like:
// some first_cont.php code here
redirect('/second_cont/valuereciever/value1')
// some second_cont.php code here
public function valureciever($value){
echo $value; // will output value1
}
In Codeigniter there are many way to pass the value from one controller to other.
You can use codeigniter Session to pass the data from one controller to another controller.
For that you have to first include the library for session
$this->load->library('session');
Then You can set the flash data value using variable name.
// Set flash data
$this->session->set_flashdata('variable_name', 'Value');
Them you can get the value where you want by using the codeigniter session flashdata
// Get flash data
$this->session->flashdata('variable_name');
Second Option codeigniter allow you to redirect the url from controll with controller name, method name and value and then you can get the value in another controller.
// Passing the value
redirect('/another_controller_name/method_name/variable');
Then you can get the value in another controller
public function method_name($variable)
{
echo $variable;
}
That all....
If you are using session in the first controller then dont unset that session in first controller, instead store the value which you want in the other controller like,
$sess_array = array('value_name1' => 'value1', 'value_name2' => 'value2');
$this->session->set_userdata('session_name', $sess_array);
then reload this session in the other controller as
$session_data= $this->session->userdata('session_name');
$any_var_name = $session_data['value1'];
$any_var_name = $session_data['value2'];
this is how you can pass values from one controller to another....
Stick to sessions where you can. But there's an alternative (for Codeigniter3) that I do not highly recommend. You can also pass the data through the url. You use the url helper and the url segment method in the receiving controller.
sending controller method
redirect("controller2/method/datastring", 'refresh');
receiving controller method
$this->load->helper('url');
$data = $this->uri->segment(3);
This should work for the default url structure. For a url: website.com/controller/method/data
To get controller $this->uri->segment(1)
To get method $this->uri->segment(2)
The limitation of this technique is you can only send strings that are allowed in the url so you cannot use special characters (eg. %#$)
I am using phil sturgeon's codeigniter template engine but i have problem how to pass variable to partial view with set_partial() method.
I used :
$this->template->set_partial('name_partial','path/to/partial',$_data_to_pass);
but when in view I use var_dump($data_to_pass) the variable seem does not exist.
I read in the documentation that it is possible to pass extra data only to partial with that function.
Your variabele _data_to_pass is an array. You're passing the content of this array to the view and not the array. So only the content of this array exists in the view.
As #Swerk says, you need to pass the data as an array. Try changing this line:
$this->template->set_partial('name_partial','path/to/partial',$_data_to_pass);
To this:
$this->template->set_partial('name_partial','path/to/partial',array('data_to_pass' = > $_data_to_pass));
And then check in your partial view var_dump($data_to_pass);
If there's somebody have the some problem, passing any $_data_to_pas as array but still does not be recognized, try to open libraries/template.php and find this line (inside public function build):
$template['partials'][$name] = $this->_find_view($partial['view'], $partial['data'],TRUE);
change to:
$template['partials'][$name] = $this->_find_view($partial['view'], $partial['data'],FALSE);
It works for me.
How can i send an indexed array or assertive array from one action to another in zend.. Both the 2 functions are in same controller..
inside action one
Zend_Registry::set("myArray",$myArray);
inside action two
$myArray = Zend_Registry::get("myArray");
This will work if you are using "forward" action helper to jump from one action to another if you are doing it through redirection then you got to store it in session or use flashMessenger action helper
I believe that you can set a param of the request object, and it is then accessible from the next acton. Preventing polluting the global registry.
$this->getRequest()->setParam('key', $value);