简体   繁体   中英

CakePHP Post parameter

I've some problem in cakephp to send/receive an input form

// /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];
    ....
}

The problem is that I receive this error:

Undefined index: service_name [APP/Controller/ServicesController]

What is wrong? Thanks!!

Use $this->request->data.

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

I suggest you please check the Documentation properly,

There are clearly mentioned that we can fetch data like...

   //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
       }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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