Here is my code.
public function usertype($renderData='')
{
$this->grocery_crud->set_table('usertype');
$output = $this->grocery_crud->render();
$this->_example_output($output,$renderData='');
}
function _example_output($output = null,$renderData='')
{
// $this->load->view('pages/our_template',$output);
//echo $output;
// $this->output=$output;
$this->_render('pages/our_template',$renderData);
}
I want to use $this->_render('pages/our_template',$renderData); instead of $this->load->view('pages/our_template',$output); But I need to pass $output to the view page. Please help me to find a way to pass $output to my view page using $renderData.
And in my view page I want to get the the data like
echo $output;
hi you can to do with view like this
$output = $this->load->view('pages/our_template',$data,TRUE); // this will return view output to variable
echo $output
Edited New Answer
First of all sorry for wrong answer
if you want to use $this->_render method then you have to take advantage of OOP create a MY_Controller under application/core directory and add _render method in it, extends your all controllers with MY_Controller like this
class MY_Controller extends CI_Controller{
function __construct(){
parent::__construct();
}
function _render($view = '', $data = array(), $return = FALSE){
if($return){
return $this->load->view($view,$data,$return);
}
$this->load->view($view,$data);
}
}
Example Page Controller
class PageController extends MY_Controller{
function __construct(){
parent::__construct();
}
function index(){
$data['title'] = 'Page title';
$data['body'] = 'Page body';
$this->_render('page_view',$data);
}
}
if you are using a layout for your project which has header,footer, sidebars then you can make render method little bit advance
function _render($view = '', $data = array(), $return = FALSE){
$output = $this->load->view($view,$data,TRUE);
if($return){
return $output;
}
$layout_data['header'] = $this->load->view('header_view',$data,TRUE);
$layout_data['footer'] = $this->load->view('footer_view',$data,TRUE);
$layout_data['sidebar'] = $this->load->view('sidebar_view',$data,TRUE);
$layout_data['body'] = $output;
$this->load->view('layout',$layout_data);
}
if you like answer accept and up it.