cakephp-3.x

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

CakePHP Authentication Plugin Identity Associations

感情迁移 提交于 2021-02-10 14:20:32
问题 I'm using CakePHP 3.8 and migrating to the Authentication Plugin (https://book.cakephp.org/authentication/1.1/en/index.html). When calling $this->Authentication->getIdentity()->getOriginalData() in a controller, I'd like to access a couple of assocations of my User entity. At the moment, I'm doing this by implementing the following IdentityInterface method in my User entity: public function getOriginalData() { $table = TableRegistry::getTableLocator()->get($this->getSource()); $table-

Best way to upgrade a Cakephp project from Cakephp 2.6.2 to 3.8

半腔热情 提交于 2021-02-05 07:54:08
问题 I have been tasked with upgrading a legacy system from Cakephp2.6.2 to Cakephp3.8. Obviously the 2 are drastically different but is there a simple way of getting the old project to work with the new cake version? Or could anyone steer me in the right direction for the best way to do this? 回答1: There is no generic "best way" that fits all. The best way is the easiest way for your specific application that results in a properly working application, but that's something that you need to

CakePHP 3.x - How to pass pagination configuration directly instead of using the controller `$paginate` property?

↘锁芯ラ 提交于 2021-01-28 19:57:45
问题 The below code works: // Somewhere in the Controller public $paginate = [ 'maxLimit'=>2 ]; // In the method: $query=$this->Model->find('all')->where(....); $this->set('results',$this->paginate($query)); However, I do not want to specify $paginate as public in the controller. I would rather not specify it at all. I tried to move maxLimit setting to the method but I'm doing it incorrectly. How can I change the below code? $query=$this->Model->find('all')->where(....); $this->set('results',$this

Cakephp How to query the paid amount?

梦想与她 提交于 2020-05-09 17:02:51
问题 I dont know whats wrong but my code dont output the paid amount column $payment_tbl = TableRegistry::get("MembershipPayment"); $payments = $payment_tbl->find(); $payments->select(['payment_total'=> $payments->func()->sum('paid_amount')]); $this->set("payments",$payments); and then echo this as echo $payments->payment_total; 回答1: $payments will be a query result object, not a single result. With this query, where you're expecting just a single row, add ->first() after your sum call. In general

Cakephp How to query the paid amount?

寵の児 提交于 2020-05-09 17:01:12
问题 I dont know whats wrong but my code dont output the paid amount column $payment_tbl = TableRegistry::get("MembershipPayment"); $payments = $payment_tbl->find(); $payments->select(['payment_total'=> $payments->func()->sum('paid_amount')]); $this->set("payments",$payments); and then echo this as echo $payments->payment_total; 回答1: $payments will be a query result object, not a single result. With this query, where you're expecting just a single row, add ->first() after your sum call. In general

CakePHP 3.x Specify a Different Count Query for Pagination

混江龙づ霸主 提交于 2020-04-07 09:26:27
问题 I am trying to customize the pagination query for CakePHP I am using a Model based around a view. The view has some complex calculations in it and when the pagination runs it takes about 3 seconds to pull the 20 rows or so. Then it is running the same view wrapped in a count for the count used in pagination. I can run a simple table count on another table which would cut the load times in half but I am unable to find a simple way to customize a seperate query to run for the counts. Is this

Cakephp 3 Authentication plugin, login URL did not match

南笙酒味 提交于 2020-02-26 03:43:07
问题 I want to use the Authentication plugin for CakePHP 3.8 and I'm having problems that are not in documentation. After follow Getting Started (https://book.cakephp.org/authentication/1/en/index.html) I have one question. Originally $fields were specified to change username and password relation in real database, same that Auth component, and login URL is where login form si loaded. First, in getting started or any part of documentation doesn't says about a login view (form), so, like old Auth

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