控制器层的数据如何让模型层访问到?
controller有一个array,我希望在model中也可以访问到Controller:
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$this->load->model('User_model'); //载入模型
$this->User_model->addUser($data); //执行模型中的方法
Model:
$this->username = $data['username'];
$this->password = $data['password'];
$this->db->insert('user', $this);
问题是貌似model中$data['username']这种是访问不了的? 模型只接受控制器传入的参数,不能和控制器共用数据。
也就是模型和控制器只有接口,没有直接的耦合关系。 你说的这情况在我的环境中没问题的。我PHP5的环境。是不是PHP4中用引用传参数就行呀。可以试试。
页:
[1]