[eluser]hardik[/eluser]
i was finally able to solve this at my own
thanks to really cool tutorials and help available at CI forums and faq...
what i have created is one base controller which will be inherited by all other controllers and that base controller will inherit ci controller class. problem i got was i was not able to understand where to put my files for base controller as well as how i can access those variables that i declare in my base class controller to directly getting in view.
so here is what i have written
Code:
this will be stored in system/applications/libraries/MY_Controller.php , i got headache for this as i put it into controller directory but after searching forums finally i found i need to store it in libraries folder....
<?php
class MY_Controller extends Controller
{
var $data=array();
function MY_Controller()
{
parent::Controller();
$this->data['menu'] = $this->_getmenu ();
}
private function _getmenu (){
//returns menu_array();
}
}
?>
now all my default controllers will be inheriting this controller...
Code:
<?php
class Welcome extends MY_Controller {
function Welcome()
{
parent::MY_Controller();
session_start();
}
function index()
{
$data['view'] = 'home';
$this->load->view('template',$data);
}
and finally my template
Code:
<html>
<head>
<title>
<?php echo $title; ?>
</title>
</head>
<body>
<?php
echo $this->load->view('header');
echo $this->data['menu']; /* this will return menu from my base controller.....just check base class there i have declare data array variable in the header portion of the class...and i m not setting this variable from any other place its just sets only once in base class.....*/
<div>
echo $this->load->view($view);
</div>
echo $this->load->view('footer');
?>
</body>
</html>
all ci guru's please review my code and tell me is it the right way ? am i doing something wrong or this is ok ?