如何将数据从angular.js发送到cakePhp控制器?

时间:2016-05-03 07:08:42

标签: javascript angularjs http cakephp

我正在使用此HTML代码将数据传递到我的角书$scope

<tr ng-repeat="data in moduleData | orderBy:sortType:sortReverse">
    <td class="filterable-cell">{{data.Schedule.name}}</td>
    <td class="filterable-cell">{{data.Schedule.reg_start_date}}</td>
    <td class="filterable-cell">{{data.Schedule.reg_end_date}}</td>
    <td class="filterable-cell">{{data.C[0].faculty_name}}</td>
    <td class="filterable-cell">{{data.C[0].venue}}</td>
    <td class="filterable-cell"><button ng-click="Book(data.Schedule)" type="button">Book</button></td>
</tr>

这是我向js控制器发送数据的bookSchedule代码。

 $scope.Book = function(data) {
  console.log(data);
    // Posting data to php file
        return $http.post('http://localhost/cakephp-2.8.2/Schedules/bookSchedule',data);

  };
在控制台中

我正在获取此数据

Object {id: "1047", created: "2016-02-12 03:34:51", modified: "2016-04-08 11:01:07", reg_start_date: "2016-04-08", reg_end_date: "2016-04-29"…}

CakePhp代码,其中定义了bookSchedule控制器。

public function bookSchedule(){
$schedule_id = $this->request->data;
debug($schedule_id);
$data = $this->Schedule->find('all', array('conditions'=>array('id'=>$schedule_id),
    'fields' => array('id', 'created', 'modified', 'reg_type_id', 'module_id', 'name')));
    $this->set('data', $data);
    $this->render('/Elements/ajaxjson','ajax');
}

debug($ schedule_id)结果

/app/Controller/SchedulesController.php (line 41)
array()
[]

我想要 $ this-&gt; request-&gt; data 来获取我从angular.js控制器发送的数据,但获取空数组。 任何人都可以告诉我我做错了吗?

0 个答案:

没有答案