Send variable to a template view |
HI , in my project i divide the html code into 3 parts :
-view/template/header -view/template/menu -view/template/footer To send variable to heder menu or footer i must set $_SESSION variables . There is a better way ?
@pippuccio76,
It depends on what type of variables you are storing in the session variables. What type of variables are you storing (User specific or system specific variables)?
From where are you calling these different views?
I find what makes most sense for me on current projects is we built extended core Controller class with "render" method I call last thing in my controller that handles the output. We have $this->data array variable that we pass to view in render method, that loads all the views and passes the data when it needs to. Your controller: PHP Code: class Welcome extends MY_Controller Controller extension: PHP Code: class MY_Controller extends CI_Controller
(08-06-2018, 08:21 AM)Pertti Wrote: From where are you calling these different views? i do this : PHP Code: class MY_Controller extends CI_Controller But i cannot set in every function a variable to show in menu (f.e. username logged)
Indeed, writing the fetch code for user details for every function would be annoying.
If you don't want to extend Controller code, which gives you single function to handle user data, you could add it to controller __construct() method. PHP Code: class MY_Controller extends CI_Controller Same logic would apply if you use controller extension. You could either add it to core controller __construct method so it gets loaded before CodeIgniter hits your controller method. |
Welcome Guest, Not a member yet? Register Sign In |