简体   繁体   English

CakePHP-从Post获取变量

[英]CakePHP - Get a variable from Post

I have a form that looks like so: 我有一个看起来像这样的表格:

<?php
echo $this->form->create('User');
echo $this->form->input('username');
echo $this->form->input('email');
echo $this->form->input('password');
echo $this->form->end('Save');
?>

And a controller where the file is submitted: 以及提交文件的控制器:

if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) { 

        }

I am trying to get the input from the form as a variable. 我正在尝试从表单获取输入作为变量。 Something like.. 就像是..

if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) { 

          $username = $this->form->input('username');

        }

Is this possible? 这可能吗? to get an input from the form and store it as a variable to use it for something else? 从表单获取输入并将其存储为变量以用于其他用途?

Thank you all in advance! 谢谢大家!

Using: Cakephp 2.x 使用:Cakephp 2.x

This is how you access value 这就是您获取价值的方式

$this->request->data['User']['username']

Where User is name you put in $this->Form->create() and username is name of field User名是您在$this->Form->create() username的名称, username是字段名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM