cakephp-3.0

CakePHP: upgrade from 3.6.x to 4.0 “Missing Template Exception”

天涯浪子 提交于 2021-02-19 07:55:30
问题 I followed the upgrade guide (after I upgraded from 3.6 to 3.8 ) but I get this error: Error: [Cake\View\Exception\MissingTemplateException] Template file "Error\error500.ctp" is missing .... If you want to customize this error message, create src\Template\Error\fatal_error.ctp After the upgrade procedure my templates moved to app_name\templates directory and renamed to *.php instead of *.ctp . I updated the app.php and app.default.php with the new paths: 'App' => [ 'namespace' => 'App',

CakePHP 3 Controller Event Implementation Example

為{幸葍}努か 提交于 2021-02-18 18:16:35
问题 The CakePHP 3.0 documentation includes an example of how to create an event using a model as an example. I've tried and tried and it's just not translating for me. Does anyone have a CakePHP 3.x example of using a custom event where a controller sets a variable in the controller triggering the event? 回答1: Let's say we have an admin dashboard that you want to inject some code into using events so that you can decouple your plugins and not hard code dashboard functionality for particular

How do you use COUNT(*) with find('list') in CakePHP 3?

前提是你 提交于 2021-02-18 11:58:51
问题 In CakePHP 3, I had a model called Articles and a field called 'subject', and I ran into a roadblock trying to retrieve a list of the 100 most commonly-used article subjects. The following code's resulting SQL selected all of the possible fields and not COUNT(*) : $articles->find('list', [ 'keyField' => 'subject', 'valueField' => 'COUNT(*)' ]) ->group('subject') ->order(['COUNT(*)' => 'DESC']) ->limit(100) ->toArray(); Then I remembered "CakePHP’s ORM offers abstraction for some commonly used

cakePHP 3.0 Action PagesController::myaction.json() could not be found, or is not accessible."

杀马特。学长 韩版系。学妹 提交于 2021-02-10 19:01:37
问题 I am migrating an existing 2.5 app over to 3.0. I am getting an 404 error when using ajax. This works fine in cakePHP 2.5 url: "/cakephp3/pages/myaction.json" I don't see any step that I might have missed. I am sure it is a routing issue with the .json extension routes.php Router::scope('/', function ($routes) { Router::extensions(['json', 'xml']); $routes->connect('/', ['controller' => 'Pages', 'action' => 'home']); $routes->connect('/hotel-training-courses', ['controller' => 'pages',

cakePHP 3.0 Action PagesController::myaction.json() could not be found, or is not accessible."

家住魔仙堡 提交于 2021-02-10 19:00:43
问题 I am migrating an existing 2.5 app over to 3.0. I am getting an 404 error when using ajax. This works fine in cakePHP 2.5 url: "/cakephp3/pages/myaction.json" I don't see any step that I might have missed. I am sure it is a routing issue with the .json extension routes.php Router::scope('/', function ($routes) { Router::extensions(['json', 'xml']); $routes->connect('/', ['controller' => 'Pages', 'action' => 'home']); $routes->connect('/hotel-training-courses', ['controller' => 'pages',

CakePHP 3 Custom Route in Pagination

穿精又带淫゛_ 提交于 2021-02-08 11:02:55
问题 in my routes file i define a route for my controller method $routes->connect('/category/:cat', ['controller' => 'Categories', 'action' => 'category']); My controller method is this public function category(){ $this->paginate = [ 'limit' => 2 ]; $this->viewBuilder()->layout('newLayout'); $cat = $this->request->params['cat']; $id = $this->Categories->findBySlug($cat)->select(['id'])->hydrate(false)->toArray(); $cid = $id[0]['id']; $category = $this->ProductCategories ->find("all") ->select(['id

CakePHP 3 Custom Route in Pagination

半城伤御伤魂 提交于 2021-02-08 11:02:11
问题 in my routes file i define a route for my controller method $routes->connect('/category/:cat', ['controller' => 'Categories', 'action' => 'category']); My controller method is this public function category(){ $this->paginate = [ 'limit' => 2 ]; $this->viewBuilder()->layout('newLayout'); $cat = $this->request->params['cat']; $id = $this->Categories->findBySlug($cat)->select(['id'])->hydrate(false)->toArray(); $cid = $id[0]['id']; $category = $this->ProductCategories ->find("all") ->select(['id

CakePHP Delete with Multiple Conditions

落爺英雄遲暮 提交于 2021-02-07 19:16:56
问题 This is driving me mad. Why does Cake need to make simple things overly complex.. I am hoping to get Cake to generate SQL that looks like this.. I expect the SQL that runs to be DELETE `ProductVouchers` FROM `product_vouchers` AS `ProductVouchers` WHERE `ProductVouchers`.`id` = 16 AND `ProductVouchers`.`client_id` IS NULL; I am using delete() like this $this->ProductVouchers->delete([ 'ProductVouchers.id'=>$id, 'ProductVouchers.client_id'=>"NULL" ]); The log shows DELETE `ProductVouchers`

CakePHP Delete with Multiple Conditions

拥有回忆 提交于 2021-02-07 19:16:08
问题 This is driving me mad. Why does Cake need to make simple things overly complex.. I am hoping to get Cake to generate SQL that looks like this.. I expect the SQL that runs to be DELETE `ProductVouchers` FROM `product_vouchers` AS `ProductVouchers` WHERE `ProductVouchers`.`id` = 16 AND `ProductVouchers`.`client_id` IS NULL; I am using delete() like this $this->ProductVouchers->delete([ 'ProductVouchers.id'=>$id, 'ProductVouchers.client_id'=>"NULL" ]); The log shows DELETE `ProductVouchers`

JSON exception in cakephp 3

时光总嘲笑我的痴心妄想 提交于 2021-02-07 08:01:38
问题 I'm doing a restfull api in cakephp... And sometime i have some throw exceptions. For example: if (!$this->request->is('post')) { throw new MethodNotAllowedException("The requested resource does not support http method " . $this->request->param('_method')); } My problem is when the url is /controller/action.json the response is : { message: "The requested resource does not support http method GET", url: "/api/auth/users/authenticate.json", code: 405 } In json format, but, when my url is