简体   繁体   English

如何从输入表单Cakephp 3获取数据

[英]how to get data from Input Form Cakephp 3

I am very new to this Cakephp framework, trying to follow and understand how to upload files using cakephp. 我对Cakephp框架非常陌生,尝试遵循并了解如何使用Cakephp上传文件。 I am using upload plugin provided by josediazgonzalez. 我正在使用josediazgonzalez提供的上传插件。 In the view file, using formhelper i have: 在视图文件中,使用formhelper我有:

<?= $this->Form->create($user, ['type' => 'file']) ?>
<fieldset>
    <legend><?= __('Add User') ?></legend>
    <?php
        echo $this->Form->control('name');
        echo $this->Form->control('username');
        echo $this->Form->control('password');
        echo $this->Form->control('role');
        echo $this->Form->input('photo', ['type' => 'file']); 
        echo $this->Form->control('dir');
    ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>

I want to print again the value that i submitted in my controller, what should i write? 我想再次打印我在控制器中提交的值,我应该写什么? Something like: 就像是:

$this->request->data;

$this->request->data is an array of data passed to your scirpt. $ this-> request-> data是传递给脚本的数据数组。 You can use it to get field that you are interested in with, eg: 您可以使用它来获取您感兴趣的字段,例如:

$data = $this->request->data;
$someVariable = $data["name"];

Or, you can access any field directly, by using data() accessor: 或者,您可以使用data()访问器直接访问任何字段:

$someVariable = $this->request->data("name");

From this point, you can do anything you want with this variable. 从这一点开始,您可以使用此变量执行任何操作。

One more thing - as $this->request->data and $this->request->data() are currently in deprecated state and will be removed in next version, I suggest to use $this->request->getData() instead. 还有一件事-由于$ this-> request-> data和$ this-> request-> data()当前处于不赞成使用的状态,并将在下一版本中删除,因此我建议使用$ this-> request-> getData( )。 Usage is similar: 用法类似:

$this->request->getData(); //will return array of data passed
$this->request->getData("field_name"); //access to specific field

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

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