How to Add Dynamic Header and Footer |
Here is my code:
controllers/Home.php PHP Code: <?php views/themes/default/templates/common/header.php PHP Code: <!DOCTYPE html> views/themes/default/templates/common/home.php PHP Code: <div class="container"> views/themes/default/templates/common/footer.php PHP Code: <footer> Right now, it shows the text Home in each section (in header, in home, and in footer). I want each page shows different titles (header shows text Header, home shows text Home, and footer shows text Footer). How to achieve it? Thanks.
I solved this problem with MY_Controller.php in folder app/core/ I created a method/action with this:
PHP Code: //... in controller extends the MY_Controller and call view with PHP Code: $this->theme('home'); see more about MY_Controller here: https://www.codeigniter.com/user_guide/g...asses.html
(03-02-2018, 03:35 PM)wallacesilva09 Wrote: I solved this problem with MY_Controller.php in folder app/core/ I created a method/action with this: The $data, where it comes from? If all views have the same $data inputs, then all views will display the same data, right? Just like in my case.
03-03-2018, 03:29 AM
(This post was last modified: 03-03-2018, 02:19 PM by jreklund. Edit Reason: Gave wrong code. )
You need to add different keys to your $data array.
PHP Code: $data['header'] = 'Header'; PHP Code: $data['title']['header'] = 'Header';
Hi,
I will show given below one simple code //... public function theme($file){ $this->load->view('themes/default/templates/common/header', $data); $this->load->view('themes/default/templates/common/'.$file, $data); $this->load->view('themes/default/templates/common/footer', $data); } //... Hope that Helps! Regards, Daniel
The solution is fairly simple:
PHP Code: $header['title'] = "Header";
09-28-2018, 07:07 AM
(This post was last modified: 10-19-2018, 12:23 AM by Gurutechnolabs. Edit Reason: some points i want to mention )
Hello,
When you want to set particular(dynamic) header footer in your home, about, contact us that type of pages then you have to set this code in about controller. class Userlist extends CI_Controller { public function __construct(){ } public function index() { $this->load->view('themes/default/templates/common/header', $data); $this->load->view('themes/default/templates/common/home', $data); $this->load->view('themes/default/templates/common/footer', $data); } This code you have to put in about controller and you get results as per your desire. Hope This will Help you. PHP Code: $data['header'] = 'Header'; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Code: Header Code Code: Footer code (01-22-2019, 12:30 AM)garimapatil Wrote: I solved this problem with MY ->Xender Discord Omegle _Controller.php in folder app/core/ I created a method/action with this: |
Welcome Guest, Not a member yet? Register Sign In |