1

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;
Hriju
  • 728
  • 1
  • 16
  • 27

1 Answers1

0

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.

umefarooq
  • 4,540
  • 1
  • 29
  • 38
  • Thanks for comment but, I did not want to use load->view, I know i can get $data in this way. But I wanted to get it through $this->_render('pages/our_template',$renderData); – Hriju Apr 18 '13 at 11:16
  • I'm with you, I need this answered as well. I don't want to use load->view – Pascal Wagner Mar 10 '14 at 15:50
  • Please check the updated answer and let me know. is it up to mark or not. – umefarooq Mar 11 '14 at 20:06