cakephp-3.4

CakePHP3.4: How to send a json object response?

半腔热情 提交于 2020-01-21 19:19:29
问题 I try to migrate to 3.4 and I have a problem to send a json object. Up to 3.3, I used the following code: $jsonSites = json_encode([ 'reqLocation' => [ 'latitude' => $latitude, 'longitude' => $longitude ], 'sites' => $sitesList, 'discoveryBooks' => $discoveryBooksList, 'deleteSites' => !empty($inDeviceSites) ? [$inDeviceSites] : [], 'deleteBooks' => !empty($inDeviceBooks) ? [$inDeviceBooks] : [] ]); $this->response->type('application/json'); $this->response->body($jsonSites); And my client

How to get params from query object in CakePHP 3

不羁的心 提交于 2020-01-16 19:36:26
问题 How do I get the 'params' from a query object in CakePHP 3? $response = $this->getTable()->find(); // there are beforeFinds...etc that make this more complex When I debug the $response , I get this (: // ... '(help)' => 'This is a Query object, to get the results execute or iterate it.', 'sql' => 'SELECT .... WHERE ... article_id = :c2', 'params' => [ ':c0' => [ [maximum depth reached] ], ':c1' => [ [maximum depth reached] ], ':c2' => [ [maximum depth reached] ] ], // ... I'd like to know

Redirect to referrer not working after Login

主宰稳场 提交于 2019-12-20 06:06:37
问题 After logging a user in, I want to redirect them back to where they came from but It's not working properly in CakePHP 3.5. Here are the required info's to help me figure out this problem. URL while login(session time out), http://dev.scys.com/db/admin?redirect=%2Fadmin%2Fstatuses This is my Auth config, $this->loadComponent('Auth', [ 'loginAction' => ['controller' => 'Admins', 'action' => 'login'], 'loginRedirect' => ['controller' => 'Admins', 'action' => 'index'], 'logoutRedirect' => [

How to set and get Cookies in Cakephp 3.5

白昼怎懂夜的黑 提交于 2019-12-13 03:59:53
问题 I have read the Cakephp documentation but it doesn't working well. Here is my code, $this->response = $this->response->withCookie('remember_me', [ 'value' => 'yes', 'path' => '/', 'httpOnly' => true, 'secure' => false, 'expire' => strtotime('+1 year') ]); $rememberMe = $this->request->getCookie('remember_me'); 回答1: Please look at the documentation. You will find it in the following link: https://book.cakephp.org/3.0/en/controllers/request-response.html#Cake\Http\Cookie\CookieCollection To

Use OR conditions on associated model in CakePHP 3

别来无恙 提交于 2019-12-13 01:53:49
问题 I have 3 models, the base model is Jobs and Customers, Contacts are the models associated with jobs. Here is the association. $this->belongsTo('Customers', [ 'className' => 'Customers', 'foreignKey' => 'customer_id', 'joinType' => 'INNER' ]); $this->belongsTo('Contacts', [ 'className' => 'Contacts', 'foreignKey' => 'contact_id', 'joinType' => 'INNER' ]); I want to search a text in all the 3 tables and return the job records which are having the search text at least any one of the tables... I

Unexpected field 'g-recaptcha-response' in POST data on CakePHP 3

吃可爱长大的小学妹 提交于 2019-12-11 16:05:03
问题 I have created a site using CakePHP 3. I have static page which has contact us form something like this: inside contactus.ctp: <?=$this->Form->create(); ?> <?=$this->Form->hidden('form_type',['value' => 'contact']) ?> <?=$this->Form->input('name',[ 'label' => false, 'placeholder' => 'Your Full Name', 'required' => true ]); ?> <?=$this->Form->input('email',[ 'label' => false, 'placeholder' => 'Your Email', 'type' => 'email', 'require' => true ]); ?> <?=$this->Form->textarea('message',[

Login redirecting in cakePHP 3.4

ε祈祈猫儿з 提交于 2019-12-08 03:23:53
问题 I'm trying to redirect to current page after logged in, using cakephp 3.4 but I'm getting like this localhost page isn't working, locahost page redirecting you too many times. Try clearing your cookies for 2 sec after that it's redirecting to home page. Please help me out here. Here my code In appController.php public function initialize() { parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authorize' => ['Controller']

Redirect to referrer not working after Login

孤人 提交于 2019-12-02 07:31:20
After logging a user in, I want to redirect them back to where they came from but It's not working properly in CakePHP 3.5. Here are the required info's to help me figure out this problem. URL while login(session time out), http://dev.scys.com/db/admin?redirect=%2Fadmin%2Fstatuses This is my Auth config, $this->loadComponent('Auth', [ 'loginAction' => ['controller' => 'Admins', 'action' => 'login'], 'loginRedirect' => ['controller' => 'Admins', 'action' => 'index'], 'logoutRedirect' => ['controller' => 'Admins', 'action' => 'login'], 'unauthorizedRedirect' => $this->referer(), 'authenticate' =

CakePHP3.4: How to send a json object response?

萝らか妹 提交于 2019-12-02 03:48:40
I try to migrate to 3.4 and I have a problem to send a json object. Up to 3.3, I used the following code: $jsonSites = json_encode([ 'reqLocation' => [ 'latitude' => $latitude, 'longitude' => $longitude ], 'sites' => $sitesList, 'discoveryBooks' => $discoveryBooksList, 'deleteSites' => !empty($inDeviceSites) ? [$inDeviceSites] : [], 'deleteBooks' => !empty($inDeviceBooks) ? [$inDeviceBooks] : [] ]); $this->response->type('application/json'); $this->response->body($jsonSites); And my client received such kind of object: { "reqLocation": { "latitude": 48.080563, "longitude": 4.4649 }, "sites": [

CakePHP 3.4.2 Testing POST's response always returning NULL

♀尐吖头ヾ 提交于 2019-11-30 09:56:50
问题 i'm currently testing an app that simply searches a record by the given id. It works fine but the testing refuses to return the response in the code. Strangely it is ONLY shown in the CLI. I'm using phpunit provided by cakephp: "phpunit/phpunit": "^5.7|^6.0" Here is the conflicting code: $this->post('/comunas/findByBarrio',[ 'barrio_id'=>1 ]); var_dump($this->_response->body());die(); //This is just a test which always returns NULL... while the CLI shows the actual response, which is a JSON.