无法在ci中分配给受保护的var

时间:2015-01-20 09:59:32

标签: php codeigniter codeigniter-2 codeigniter-url codeigniter-form-helper

protected $_table_name = $this->session->userdata('table_name');

我的代码在尝试将会话数据分配给此var时,它显示错误。

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\Code\application\models\addfilters_m.php on line 4

像这样,在这里我附上了我的整个模型页面

<?php
class addfilters_m extends MY_Model
{
protected $_table_name = $this->session->userdata('table_name');
protected $_order_by = 'id';
public $rules = array(
    'title' => array(
        'field' => 'title', 
        'label' => 'Title', 
        'rules' => 'trim|required|max_length[100]|xss_clean'
    ), 
    'slug' => array(
        'field' => 'slug', 
        'label' => 'Slug', 
        'rules' => 'trim|required|max_length[100]|url_title|callback__unique_slug|xss_clean'
    ), 
    'body' => array(
        'field' => 'body', 
        'label' => 'Body', 
        'rules' => 'trim|required'
    )
);

public function get_new ()
{
    $addfilters = new stdClass();
    $addfilters->title = '';
    $addfilters->slug = '';
    $addfilters->body = '';
    return $addfilters;
}

}

1 个答案:

答案 0 :(得分:2)

使用这种方法应该对您有所帮助并解决问题。

protected  $_table_name;

public function __construct()
{
    $this->_table_name= $this->session->userdata("table_name");
    parent::__construct();
}