Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用CakePHP创建restapi_Php_Rest_Cakephp_Backend - Fatal编程技术网

用CakePHP创建restapi

用CakePHP创建restapi,php,rest,cakephp,backend,Php,Rest,Cakephp,Backend,我必须使用CakePHP为移动后端创建RESTAPI。在遵循说明之后,我已经能够设置创建RESTAPI的要求。问题是,当我使用\u serialize变量时,我的输出中得到了一个null。这是我的密码: class InvitationController extends AppController { public $components = array('RequestHandler'); public function index() { } pub

我必须使用CakePHP为移动后端创建RESTAPI。在遵循说明之后,我已经能够设置创建RESTAPI的要求。问题是,当我使用
\u 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
发出请求时,我在输出中得到
null
,状态为
200
。另一方面,如果我只是在
控制器
视图
中执行
echo json_encode($message)
,我会得到正确的输出。我想我做错了什么。请帮忙

这是错误的:

 '_serialize' => array($message)
请注意,它在提供的示例中正确地显示了它

 '_serialize' => array('message')

我的错。我应该看到的。谢谢!