我有:
echo $this->Form->input('username', array('label' => 'Username: '));
相当于传统的PHP编码。
我怎样才能获得在该文本框中输入的值,就像当你做$val = $_POST['用户名']; 在传统的 PHP 编码中。
我需要这个进行登录验证。 谢谢
你可以得到它
$val = $this->data['ModelName']['username']; //CakePHP 1.X.X
//or
$this->request->data['ModelName']['username']); //CakePHP 2.X.X
其中"模型名称"是当前分配给表单的模型。
更新:
$user = $this->Account->find('first', array(
'conditions' => array(
'username' => 'user1'
)
));
从 CakePHP 4.x 开始,你应该使用
$this->request->getData()
例如
$title = $this->request->getData('title');
如果数据是嵌套的(即指定模型),请使用点表示法
$userName = $this->request->getData('user.name');