cakephp-3.0

Count in contain Cakephp 3

纵然是瞬间 提交于 2019-12-30 06:11:49
问题 I have a table Post and this has a has-many association with a table Stars . I can get all the associated data using: $this->Posts->find()->contain(['Stars']); That works well. But I want to count the Stars. I have tried this but its not working: $this->Posts->find->contain([ 'Stars' => function($q) { return $q->select(['total' => $q->func()->count('Stars.post_id')]); } ]); //I've also tried this ... ...$q->select(['total' => "COUNT(Stars.post_id)"]); ... //Also fail This does not return the

Multiple database connection in cakephp 3

若如初见. 提交于 2019-12-28 13:24:07
问题 I am trying to connect to multiple databases in cakephp 3 . I have tried many times but all questions and answers are in cakephp 2 . I found Configuring Connections at cakephp 3 documentation. But I can't understand it. I have two databases : 1. tracking_system (Tables: trackers, events, etc..) 2. tracking_system_2 (Tables: todos, actions, etc..) Working with database tracking_system is completely running. But I don't know, how to connect to multiple databases (in my case, with second

Multiple database connection in cakephp 3

╄→尐↘猪︶ㄣ 提交于 2019-12-28 13:24:06
问题 I am trying to connect to multiple databases in cakephp 3 . I have tried many times but all questions and answers are in cakephp 2 . I found Configuring Connections at cakephp 3 documentation. But I can't understand it. I have two databases : 1. tracking_system (Tables: trackers, events, etc..) 2. tracking_system_2 (Tables: todos, actions, etc..) Working with database tracking_system is completely running. But I don't know, how to connect to multiple databases (in my case, with second

Show SQL query of controller

狂风中的少年 提交于 2019-12-26 06:35:29
问题 I am using cakephp v3.x and mysql. I would like to see the SQL query of a controller. There is no error with this controller and it runs successfully. public function appGetResult() { $this->autoRender = false; $start_date = $this->request->query['start_date']; $end_date = $this->request->query['end_date']; $results = $this->MonthlyReports->getResult($start_date, $end_date); echo json_encode($results); } How to modify the controller code to display the SQL query used in generating the results

Show SQL query of controller

无人久伴 提交于 2019-12-26 06:31:54
问题 I am using cakephp v3.x and mysql. I would like to see the SQL query of a controller. There is no error with this controller and it runs successfully. public function appGetResult() { $this->autoRender = false; $start_date = $this->request->query['start_date']; $end_date = $this->request->query['end_date']; $results = $this->MonthlyReports->getResult($start_date, $end_date); echo json_encode($results); } How to modify the controller code to display the SQL query used in generating the results

Show SQL query of controller

家住魔仙堡 提交于 2019-12-26 06:30:46
问题 I am using cakephp v3.x and mysql. I would like to see the SQL query of a controller. There is no error with this controller and it runs successfully. public function appGetResult() { $this->autoRender = false; $start_date = $this->request->query['start_date']; $end_date = $this->request->query['end_date']; $results = $this->MonthlyReports->getResult($start_date, $end_date); echo json_encode($results); } How to modify the controller code to display the SQL query used in generating the results

Save associated in cakephp 3 not working

时间秒杀一切 提交于 2019-12-25 17:18:24
问题 My save associated in cakephp3 (3.1.5 and 3.0) is not working. users table relation with user_profiles table is hasOne and user_profiles table relation with users table is belongsTo. When I want to save a user record with associated user_profile record, user record saves in users table but no record is saved in associated table user_profiles . I have no error in error.log Entities for both of them => protected $_accessible = [ * => true ]; Users Controller public function add() { $data = [

CakePHP 3 - Count many-to-many Association

家住魔仙堡 提交于 2019-12-25 16:39:53
问题 I have a database with Rounds and Users. Rounds belongsToMany Users and Users belongsToMany Rounds, so a many-to-many relation. A join table rounds_users was added to do this. EDIT: Used the incorrect phrase here. I meant 'belongsToMany' instead of 'hasMany' Now I want to retrieve a list of Rounds, together with the number of linked Users per round. In case of a one-to-many relation something like the following would work: $rounds = $this->Rounds->find() ->contain(['Users' => function ($q) {

Creating a http Client in Cake 3

空扰寡人 提交于 2019-12-25 11:27:08
问题 I am having trouble getting a response from an API using a http Client in Cake PHP 3 I want to send the following GET request but I cannot manage to return a result. If visit this url with a browser i get a response. http://XX.XX.XX.XX:8020/mvapireq/?apientry=newuseru&authkey=XXXXXXXXXX&u_username=NEWUSERNAME&u_password=PASSWORD&u_name=NAME&u_email=EMAIL&u_phone=PHONE&u_currency=USD&u_country=USA&u_address=x&deviceid=DEVICEID&now=555 When I try to send the same request with http Client my

Creating a http Client in Cake 3

落爺英雄遲暮 提交于 2019-12-25 11:25:22
问题 I am having trouble getting a response from an API using a http Client in Cake PHP 3 I want to send the following GET request but I cannot manage to return a result. If visit this url with a browser i get a response. http://XX.XX.XX.XX:8020/mvapireq/?apientry=newuseru&authkey=XXXXXXXXXX&u_username=NEWUSERNAME&u_password=PASSWORD&u_name=NAME&u_email=EMAIL&u_phone=PHONE&u_currency=USD&u_country=USA&u_address=x&deviceid=DEVICEID&now=555 When I try to send the same request with http Client my