Templates in CI version 4 |
Hey guys
First, I'm not sure if 'template' is the technical term for this. In CI version 3, I created a MY_Loader file in the core folder and I used that to load the Header, View, and Footer with just one line of code: MY_Loader.php Then inside the controllers I'd use it like this: Controller How do I do this with CI 4? So far I've been loading the views for the Header, View, and Footer files individually in each instance, which is not ideal if I want to switch templates (from v1 to v2, for example).
You can do it almost the same way.
Add your template method to the CI 4 BaseController. Then extend all your controllers from the BaseController. I tested it here and it worked fine. BaseController: PHP Code: public function template(string $page, array $data) Then call it like this: PHP Code: $this->template('auth/login, $data); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Take a look at View Layouts which accomplish much the same thing and it might even be more versatile and easier to use than the extended loader method.
|
Welcome Guest, Not a member yet? Register Sign In |