I’m new with cakephp 3 and I don’t know how can I do this SQL query:
SELECT n1.mot, r.nomc, n2.mot, d.def
FROM `aretes` as a, `noeuds` as n1, `noeuds` as n2, `definitions` as d, `relations` as r
WHERE a.mot1 = n1.id and
a.mot2 = n2.id and
a.rel = r.id and
n1.id = d.noeud_id and
n1.id = 41114
group by a.rel
order by n2.poids desc
I need to use this query in NoeudsController.
Thank you in advance.
I’d use the querybuilder for that kind of query. If you haven’t used QB before, I’d practice on some simple queries first.
Also have a look at this, not cake, but shows how a complex query was worked up using QB.
Just remember cake QB syntax is a little different.
Also you can write raw pdo see http://book.cakephp.org/3.0/en/orm/database-basics.html
Ok, thank you!
Now I have a problem with paginator…
I have a fix for paginator, I use a different one where I have full control. See this paginator and learn how to use it, I have used in asp.ner, jsp / servlets, just had to change the language etc
There are instructions in the comments how to use skip take —
* getLimit2 and getPerPage are used together
* when using the Eloquent Query Builder
* for the skip and take parameters.
* There are also other ORM's that need the skip and take
* parameters separated.
* Example in controller method calling model method:
* $data['pets'] = $this->pet->getPets($pages->getLimit2(), $pages->getPerPage(), $petSearch);
* Example model method using Eloquent Query Builder:
* public function getPets($offset = "", $rowsPerPage = "", $petSearch = "")
* $petsearch = $petsearch . "%";
* return Capsule::table('pets')
* ->where('petName', 'like', $petsearch)
* ->orderBy('petName', 'asc')
* Also see the file in the helpers folder page_eloq.md for more help.
If you need more help just start a new topic, but believe me this is a good paginator.
Also see http://laravel.io/forum/11-13-2014-laravel-5-pagination where I show it, but updated since no _ now