[英]how to get the value on form input in cakephp
I have:我有:
echo $this->Form->input('username', array('label' => 'Username: '));
equivalent to in traditional php coding..相当于传统的php编码..
how can I get the value inputted in that textbox like when you do $val = $_POST['username'];我怎样才能像执行 $val = $_POST['username']; 那样获取在该文本框中输入的值; in traditional php coding.
在传统的 php 编码中。
I need this for login validation.我需要这个来进行登录验证。 thanks
谢谢
You can get it你可以的
$val = $this->data['ModelName']['username']; //CakePHP 1.X.X
//or
$this->request->data['ModelName']['username']); //CakePHP 2.X.X
Where "ModelName" is your currently assigned model to form.其中“ModelName”是您当前指定的要形成的模型。
Update:更新:
$user = $this->Account->find('first', array(
'conditions' => array(
'username' => 'user1'
)
));
From CakePHP 4.x, you should use从 CakePHP 4.x 开始,您应该使用
$this->request->getData()
For example例如
$title = $this->request->getData('title');
If the data are nested (ie, specifying a model), use a dot notation如果数据是嵌套的(即指定模型),请使用点表示法
$userName = $this->request->getData('user.name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.