duanba4254 2013-04-18 10:32
浏览 239

如何在codeigniter中使用$ this_render-> view(“pagename”,$ renderData)将数据传递给视图?

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;
  • 写回答

1条回答 默认 最新

  • dongshang6790 2013-04-18 10:40
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?