簡體   English   中英

使用CakePHP創建REST API

[英]Creating REST API with CakePHP

我必須使用CakePHP為移動后端創建REST API。 按照此處的說明進行操作后我就可以設置創建REST API的要求。 問題是,當我使用_serialize變量時,輸出中的null 這是我的代碼:

class InvitationController extends AppController {

    public $components = array('RequestHandler');

    public function index() {

    }

    public function add() {

        if ($this->request->is('post')) {
            $this->loadModel('Organizer');

            $numPeople = $this->request->data['numpeople'];
            $share = $this->request->data['myshare'];
            $organizer = $this->request->data['organizer'];     
            $organizerMobile = $this->request->data['organizermobile'];
            $this->set('organizerMobile', $organizerMobile);    
            $deadline = $this->request->data['deadline'];

            $links = array();       

            date_default_timezone_set("Asia/Calcutta");
            $now = date('Y-m-d');
            $lastOrganizer = $this->Organizer->find('first', array(
                'order' => array('Organizer.id' => 'desc')
            ));

            $checkOrganizer = $this->getOrganizerDetails($lastOrganizer);

            $pass = //something;


            // save data in organizers table
            $this->organizer->create();
            $this->organizer->save(
                array(
                    'name' => $organizer,
                    'mobile' => $organizerMobile,
                    'p_id' => 1,
                    'share' => $share,
                    'deadline' => $deadline,
                    'password' => $pass,
                    'group_cardinality' => $numPeople,
                    'created_on' => $now,
                )
            );

            $message = 1;
            $this->set(array(
                'message' => $message,
                '_serialize' => array($message)
            ));
        }
    }
}   

當我請求POST /invitation.json時,輸出中的狀態為200 null 另一方面,如果我只是簡單地在ControllerView echo json_encode($message) ,則會得到正確的輸出。 我想我做錯了。 請幫忙!

錯了:

 '_serialize' => array($message)

請注意本手冊 ,它在所提供的示例中正確顯示。

 '_serialize' => array('message')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM