cakephp-3.x

CakePHP 3.3.15 multiple matching() chained with OR

允我心安 提交于 2020-01-14 02:37:27
问题 I'm trying to implement a global search mechenism in my CakePHP 3.3.15 app - this involves searching the Parent table for a value plus searching all the associated tables for the same value. I'm using matching() , but I can't find a way to combine multiple matching() into one query object using OR . It looks like matching() will narrow down the result set and calling matching() consecutively will use the object modified by the previous matching() call. This is what I have: $query = $this->

getting value from string array in cake php

妖精的绣舞 提交于 2020-01-07 03:56:09
问题 If I have this output of an array : $array_to_delete = [ (int) 3 => (int) 4, (int) 4 => (int) 5 ] And i want to get 4 and 5 and so on at where condition , Like that : $warehouseItemsData = $this->WarehouseEmployers->WarehouseItems->find() ->where(['id', $array_to_delete]) ->all(); How can i do that ? in cake php 回答1: use IN $warehouseItemsData = $this->WarehouseEmployers->WarehouseItems->find() ->where(['id IN', $array_to_delete]) ->all(); 来源: https://stackoverflow.com/questions/45481414

CakePhp 3.x Continue session from out of the app

笑着哭i 提交于 2020-01-07 03:51:23
问题 I'm building a new version of a website in cakephp 3.x . Since I rebuild in phases,I need interaction between parts of the new site and the old site. The best way to do this at this moment is with the use of $_SESSION . My problem is that the cakephp part makes a new session instead of using the active one from the native PHP part. It writes it next to it in the same folder. this is my app.php setting in cakephp 'Session' => [ 'defaults' => 'php', 'timeout' => '2000', 'ini' => [ 'session

How to pass friendsofcake/search results onto different view in CakePHP 3.x?

纵饮孤独 提交于 2019-12-25 06:44:55
问题 I've successfully implemented friendsofcake/search plugin into my app but I'm having a hard time passing the results of my search onto another page. Is this possible? If so, where would I configure it on my app? Say, on my index.ctp where my search form is, I want the output to be on search.ctp. Thanks! 来源: https://stackoverflow.com/questions/39505065/how-to-pass-friendsofcake-search-results-onto-different-view-in-cakephp-3-x

CakePHP 3 putting un-necessary parentheses in SQL causing error

帅比萌擦擦* 提交于 2019-12-25 01:44:09
问题 CakePHP 3.7. Trying to use the ORM to write a query which contains a MySQL COALESCE condition. Followed advice on CakePHP 3 - How to write COALESCE(...) in query builder? and ended up having to write it manually using newExpr() as this was the given solution. The code I have is as follows: $TblRegulatoryAlerts = TableRegistry::getTableLocator()->get('TblRegulatoryAlerts'); $subscribed_to = $TblRegulatoryAlerts->getUserRegulations($u_id, $o_id, false); $query = $this->find() ->contain('Filters

CakePHP 3 putting un-necessary parentheses in SQL causing error

为君一笑 提交于 2019-12-25 01:29:01
问题 CakePHP 3.7. Trying to use the ORM to write a query which contains a MySQL COALESCE condition. Followed advice on CakePHP 3 - How to write COALESCE(...) in query builder? and ended up having to write it manually using newExpr() as this was the given solution. The code I have is as follows: $TblRegulatoryAlerts = TableRegistry::getTableLocator()->get('TblRegulatoryAlerts'); $subscribed_to = $TblRegulatoryAlerts->getUserRegulations($u_id, $o_id, false); $query = $this->find() ->contain('Filters

CakePHP 3: belongsToMany (through) and additional associations

拟墨画扇 提交于 2019-12-24 08:38:49
问题 I have defined the following associations: class RecipesTable extends Table { $this->belongsToMany('Ingredients', [ 'through' => 'RecipesIngredients', 'foreignKey' => 'recipe_id', 'targetForeignKey' => 'ingredient_id', ]); class IngredientsTable extends Table { $this->belongsToMany('Recipes', [ 'through' => 'RecipesIngredients', 'foreignKey' => 'ingredient_id', 'targetForeignKey' => 'recipe_id', ]); class RecipesIngredientsTable extends Table { $this->belongsTo('Recipes'); $this->belongsTo(

Organize a groupBy within another groupBy using Collection in CakePHP

可紊 提交于 2019-12-24 07:49:59
问题 I have the following array and I would like to be able to organize it through collection $collection = Collection($total); $filter = $collection->groupBy('date_general')->toArray(); [2017-11-14] => Array ( [0] => Array ( [status] => pending [date_general] => 2017-11-14 [user_id] => 164 ) [1] => Array ( [status] => pending [date_general] => 2017-11-14 [user_id] => 112 ) ) Up to this point I already have the array organized by dates. Now within each date I need to organize it by user, that is

CakePHP 3 - How to write COALESCE(…) in query builder?

拟墨画扇 提交于 2019-12-24 00:57:20
问题 How do I write this kind of COALESCE() statement in the query builder? SQL SELECT COALESCE(n.value, p.value) AS value FROM nodes n LEFT JOIN parents p ON p.id = n.parent_id PHP I can retrieve both the child and parent values and then go through the result set and just use the parent one if the child one is empty, but if there is a more elegant way to build it into the query itself, I would prefer that. $child = $this->Nodes->find() ->select(['id', 'value']) ->where(['Nodes.id' => $id]) -

Check if object exists or is empty in view template

╄→尐↘猪︶ㄣ 提交于 2019-12-22 09:45:38
问题 How do you check within the view template if the result object contains any entries? (There was a similar question already, but this one is slightly different) Take the CakePHP 3 blog tutorial for example. They show how to list all articles on one page: // src/Controller/ArticlesController.php public function index() { $this->set('articles', $this->Articles->find('all')); } And the view template: <!-- File: src/Template/Articles/index.ctp --> <table> <tr> <th>Id</th> <th>Title</th> </tr> <