如何将变量发送到Grocery Crud中查看?

时间:2016-05-29 15:24:53

标签: codeigniter-3 grocery-crud

我正在使用Grocery Crud作为我的Web应用程序,我想将一些数据从用户模型发送到视图,但是,因为杂货使用$ output变量,它被初始化为$output = $crud->render();并始终将其发送到视图;因此,我无法向视图发送其他数据。

这是我在控制器中的代码以及我尝试过的但是没有成功。

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

            class User1 extends CI_Controller {

                public function __construct()
                {
                    parent::__construct();
                    $this->load->library('grocery_CRUD');
                    $this->load->model('M_User');
                }

                public function index()
                {
                    $this->user();
                }

                public function user($id)
                {
                    // get user information
                    $user = $this->M_User->get_user_info($id);

                  // array variable that I want to send to view a long with variable $output
                    $u = array(
                        'owner_name'=>$user->owner_name,
                        'owner_phone'=>$user->owner_phone,
                        'owner_email'=>$user->owner_email,
                        'owner_facebook'=>$user->owner_facebook,
                        'owner_picture'=>$user->owner_picture,
                        'owner_gender'=>$user->owner_gender
                        );

            // Start Grocery Crud
            $crud = new grocery_CRUD();

            $crud->set_table('room');
            $crud->set_subject('subject');

            $crud->where('owner_id',$id);
            $output = $crud->render();



            // $output = array_merge($output,$u); This is what I tried to do but it did not work.

            $this->load->view('user1',$output);

}
}
?>

有没有办法可以将变量$u与变量$output一起发送?

请劝告, 谢谢和最诚挚的问候。

2 个答案:

答案 0 :(得分:0)

将数据作为参数发送到渲染函数 试试这个

$output = $crud->render($u);

答案 1 :(得分:0)

  

控制器

//...
//do all your Grocery Crud staff
//...
$output = $crud->render();

//rending extra value to $output
$data['variable1']='variable_value';
$data['variable2']=12;

$output->data = $data;

$this->load->view('...your page...',$output);
  

查看

echo $data['variable1'];
echo $data['variable2'];