在codeigniter中将所有数组元素从控制器传递到视图


Pass all array elements to view from controller in codeigniter

我想从控制器传递一个数组给视图。我尝试使用下面的代码。我知道这是不对的,但想不出该用什么。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 = $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');
应:

$data = array('myvar' => $this->blog_model->find());
$this->load->view('template/header');
$this->load->view('template/content', $data);
$this->load->view('template/footer');

然后在视图中使用:

$myvar