Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过codeigniter中的控制器将所有阵列元素传递给视图_Php_Codeigniter - Fatal编程技术网

Php 通过codeigniter中的控制器将所有阵列元素传递给视图

Php 通过codeigniter中的控制器将所有阵列元素传递给视图,php,codeigniter,Php,Codeigniter,我想从控制器向视图传递一个数组。我尝试使用下面的代码。我知道这是错误的,但我想不出该用什么find()函数从表中获取所有行,然后我想将这些行作为数组传递给视图。我怎样才能做到 <?php class Blog extends CI_Controller{ public function __construct(){ parent::__construct(); $this->load->model('bl

我想从控制器向视图传递一个数组。我尝试使用下面的代码。我知道这是错误的,但我想不出该用什么find()函数从表中获取所有行,然后我想将这些行作为数组传递给视图。我怎样才能做到

<?php
    class Blog extends CI_Controller{

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

        public function index(){

             $data = $this->blog_model->find(); //which gets all entries from table
            $this->load->view('template/header');
            $this->load->view('template/content', $data);
            $this->load->view('template/footer');

        }

        public function create(){
            $this->blog_model->create();


        }

        public function delete(){


        }
    }
    ?>

应该是:

$data = array('myvar' => $this->blog_model->find());
$this->load->view('template/header');
$this->load->view('template/content', $data);
$this->load->view('template/footer');
然后使用以下工具在视图中访问它:

$myvar
请看详细的解释

应该是:

$data = array('myvar' => $this->blog_model->find());
$this->load->view('template/header');
$this->load->view('template/content', $data);
$this->load->view('template/footer');
然后使用以下工具在视图中访问它:

$myvar
请看详细的解释