codeigniter为视图发送变量

时间:2017-02-26 20:36:24

标签: codeigniter variables object

我的控制器页面是:

class Anasayfa extends CI_Controller {

public $viewData;

function __construct() {
    parent::__construct();
    $this->viewData = new stdClass();
    $this->viewData->sayfa = 'main';
}

public function index()
{
    $this->load->view('common/template', $this->viewData);
}

我的观看页面是:

$this->load->view('common/header'); $this->load->view('common/navbar'); $this->load->view('common/solmenu'); $this->load->view('common/slider'); $this->load->view($sayfa); $this->load->view('common/footer');

但是在浏览器中:

  

严重性:注意

     

消息:未定义的变量:sayfa

     

文件名:common / template.php

     

行号:6

2 个答案:

答案 0 :(得分:2)

使用数组:

function __construct() {
    parent::__construct();
    $this->viewData = array();
    $this->viewData['sayfa'] = 'main';
}

答案 1 :(得分:0)

传递数组而不是对象:

$this->viewData['sayfa'] = 'main';

Adding Dynamic Data to the View