php - how to pass data to view using $this_render->view("pagename",$renderData) in codeigniter? -
here 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 use $this->_render('pages/our_template',$renderdata); instead of $this->load->view('pages/our_template',$output); need pass $output view page. please me find way pass $output view page using $renderdata.
and in view page want the data like
echo $output;
hi can view this
$output = $this->load->view('pages/our_template',$data,true); // return view output variable echo $output
edited new answer
first of sorry wrong answer
if want use $this->_render method have take advantage of oop create my_controller under application/core directory , add _render method in it, extends controllers my_controller 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 using layout project has header,footer, sidebars 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 answer accept , it.
Comments
Post a Comment