how to make it little more clean |
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 ?
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>
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
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 (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 (04-09-2015, 11:15 AM)CroNiX Wrote:(04-09-2015, 02:59 AM)waqaspuri Wrote: Thanks -> but helpful
$route['(:any)'] = 'web/$1'; //send requests for "home" to the "web" controller, "home" method
works perfect |
Welcome Guest, Not a member yet? Register Sign In |