我已经使用codeigniter几个月了,突然,它不让我传递任何类型的信息到我的视图。它为事实加载适当的视图,但我的变量都不能返回,如果我这样做,我总是得到NULL。然而,当我的同事这样做时,他看到的变量很好。我们共享同一个存储库。什么好主意吗?我目前正在使用消息方法
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class App_loader extends CI_Controller {
public $data = array();
function __construct()
{
parent::__construct();
}
public function dashboard() {
$this -> load -> view ('apps/dashboard/index');
}
public function appstore() {
$this -> load -> view ('apps/appstore/index');
}
public function calendar() {
$this -> load -> view ('apps/calendar/index');
}
public function messages() {
$this->data["name"] = "Vincent";
$this->load->view('apps/messages/index',$this->data);
}
public function profile() {
$this -> load -> view ('apps/profile/index');
}
public function vendors() {
$this -> load -> view ('apps/vendors/index');
}
public function settings() {
$this -> load -> view ('settings');
}
}
在我的视图中只有一个die语句die($name);还有一些html。得到NULL。(是的,它被适当的PHP标记所包围。有人见过这样的东西吗?
不需要为变量使用$this关键字。您可以简单地像这样使用:
$data['name'] = 'Vincent';
$this->load->view('apps/messages/index',$data);
在你的视图中,你可以使用$name
来获取name的值echo $name;
您必须使用正常的数据数组,如:
$data=array();
$data["name"] = "Vincent";
$this->load->view('apps/messages/index',$data);
not like:
$this->data["name"] = "Vincent";
$this->load->view('apps/messages/index',$this->data);
if used like this you have to put
$data = array(); in constructor
就是这样!