Change the main content per controller change |
I've been making school projects and I need ideas on how it can be done
I have 2 view files that is always included when making controller methods I create a function where the main content will load based on the parameter supplied Here's the code: Code: public function nextPage($link){ Then using the method like this: Code: public function user_index(){ I've been thinking that it is not a good approach since I think the header and footer will also load upon loading the said section
Make a MY_Controller (in application/core).
Create a method in it that renders the pages, the way you want. PHP Code: class MY_Controller extends CI_Controller { Let all your controllers extend this MY_Controller. If you want to load a certain page with the default header and footer, just use $this->render_page('viewfile-name'); All the data that you want to pass to the view, can be added to the $this->data array, like: PHP Code: $this->data['records'] = $this->sample_model->get_all();
This is how I do it:
PHP Code: public function foo()
I forgot to mention that the method is in MY_Controller.
I didn't try yet those ways you provide guys but would it accomplish what I want to achieve. Like this, assumed I have a dashboard and when the index page is loaded all resources like jquery would also be loaded. Then when navigating to links inside the dashboard only the content wrapper that will change and it will not load the resources again. Quote:assumed I have a dashboard and when the index page is loaded all resources like jquery would also be loaded. Then when navigating to links inside the dashboard only the content wrapper that will change and it will not load the resources again. Nice thought, but it would mean that all content within the dashboard is shown via one URL. Once you change the URL (e.g. because you switch to another method inside the controller), a new page is loaded. If you just want to change some elements on your page without refreshing the whole page, you will need AJAX.
|
Welcome Guest, Not a member yet? Register Sign In |