![]() |
how to make it little more clean - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: how to make it little more clean (/showthread.php?tid=61332) |
how to make it little more clean - waqaspuri - 04-09-2015 Hey;- > on each controller function, am loading the SQL data, as you can see below in a code box Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Problem: Is there any way out to fetch the data in index function and shouldn't use the model and function again and again ? RE: how to make it little more clean - Athov - 04-09-2015 my example is: make a MY_Controller in app/core and in MY_Controller do something like PHP Code: class MY_Controller extends CI_Controller in the controller you do $this->layout('some_view'); layout/view.php is like Code: <!DOCTYPE HTML> RE: how to make it little more clean - waqaspuri - 04-09-2015 Explain in details how does it works in few lines?? RE: how to make it little more clean - Athov - 04-09-2015 the last parameter in $this->load->view() is used to not display the view but return in see this $data['main_menu'] = $this->load->view('layout/menu', null, true); // here you get the HTML for the menu that is in app/views/layout/menu.php $data['main_content'] = $this->load->view($content_name, null, true); // here you get the HTML for the currently displayed page and this if you don't know <?=$main_content; ?> is <?php echo $main_content; ?> see this and app/views/layout/view.php is the template you can make anything in it also this is an example you can make it in many other ways PS: i'm not really good at explaining RE: how to make it little more clean - waqaspuri - 04-09-2015 Thanks -> but helpful am not using __contruct() in my site -> i can load my function in this way localhost/web/home (web = is a class) problem: how do I load it in this way -> localhost/home RE: how to make it little more clean - CroNiX - 04-09-2015 (04-09-2015, 02:59 AM)waqaspuri Wrote: Thanks -> but helpful With a route. See the docs. PHP Code: $route['the-requested-url-to-route'] = 'controller/method'; So PHP Code: $route['home'] = 'web/home'; //send requests for "home" to the "web" controller, "home" method RE: how to make it little more clean - waqaspuri - 04-10-2015 (04-09-2015, 11:15 AM)CroNiX Wrote:(04-09-2015, 02:59 AM)waqaspuri Wrote: Thanks -> but helpful RE: how to make it little more clean - waqaspuri - 04-10-2015 $route['(:any)'] = 'web/$1'; //send requests for "home" to the "web" controller, "home" method works perfect |