CakePHP Post参数

时间:2014-06-25 13:16:20

标签: php forms cakephp

我在cakephp中遇到输入/接收输入表单的问题

// /View/Services/add_services.ctp
....
<?php echo $this->Form->create('Service', array('action'=>'addServices'))?>
<?php echo $this->Form->input("service_name", array('label'=>false, 'div'=>false, 'class'=>"umstyle5"))?>
<?php echo $this->Form->Submit(__("Add service Type"))?>
<?php echo $this->Form->end();?>

// /Controller/ServicesController
....
public function addServices(){
    ....
    $service_name = $_POST[service_name];
    ....
}

问题是我收到此错误:

未定义的索引:service_name [APP / Controller / ServicesController]

有什么问题? 谢谢!

2 个答案:

答案 0 :(得分:2)

使用$ this-&gt; request-&gt; data。

 public function addServices(){
....
  $service_name = $this->request->data['Service']['service_name'];
....
 }

答案 1 :(得分:-1)

我建议你正确查看Documentation

有明确提到我们可以获取数据......

   //Controller/RecipesController.php:
   public function edit($id = null) {
       if (empty($this->request->data)) {
          $this->request->data = $this->Recipe->findById($id);
       } else {
          // Save logic goes here
       }
    }