【问题标题】:sending a text data between template to controller in cakephp 3在 cakephp 3 中将模板之间的文本数据发送到控制器
【发布时间】:2018-07-18 13:55:00
【问题描述】:

定义:

我想将文本数据从模板(ctp 文件)发送到控制器,但它不起作用。

到目前为止我所做的事情:

我有这个控制器课程,它有如下的搜索功能:

/src/Controller/CoursesController :

    public function search()
     {

    $search = $this->request->getData('keyword');

    debug($search);die;

...

/src/模板/搜索:

 <?= $this->Form->create(null, ['url' => ['controller'=>'courses','action' => 'search']]) ?>

 <?= $this->Form->control('keyword', ['label' => false, 'type'=>'text','class'=>'form-control', 'placeholder' => __('Search for...')]); ?>

 <?= $this->Form->button(__('Go'), ['class' => 'btn btn-default', 'type' => 'submit']) ?>


   <?= $this->Form->end() ?>

尽管我尝试从表单中获取文本数据并使用调试打印它,但不幸的是我有一个空数组

【问题讨论】:

  • 不确定这是否能解决您的问题,但控制器名称应在您的 URL 参数中大写:['url' =&gt; ['controller'=&gt;'Courses','action' =&gt; 'search']]
  • 因为view和action是一样的所以不需要设置url。无论如何,你的代码应该可以工作,除非你有一些组件在后台做某事

标签: input request cakephp-3.2


【解决方案1】:

试试这个:

public function search()
{
    $data = $this->request->data;
    if($this->request->is(['patch', 'post', 'put', 'get'])) 
    {
        $search = $this->request->data('keyword');
        debug($search);   
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2015-10-16
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多