-
投稿日 2019-06-13 02:05
kiyokawa's Blog
by
kiyokawa
Say you want two sets of pagination against the same model, each with a different condition.Here is how to do it, assuming we have a table called articles, and we want pagination for current articles and for past (expired) articles. In your controller, write this: $this->paginate = [ 'Articles' => [...
-
投稿日 2019-06-11 03:38
kiyokawa's Blog
by
kiyokawa
cd app/bin./cake cache clear_all
-
投稿日 2019-06-09 13:03
kiyokawa's Blog
by
kiyokawa
Cake is built in with MobileDetect nowadays, so it is as simple as this:
-
投稿日 2019-06-07 12:55
kiyokawa's Blog
by
kiyokawa
Say we have the following data in a table called countries:idcountrycapitol1USAWashington DC2JapanTokyo3United KingdomLondonAnd you want to fetch data like this:['Washington DC', 'Tokyo', 'London']Then do this:$capitols = $this->countries ->find() ->extract('capitol') ->toArray();
-
投稿日 2019-06-05 12:49
kiyokawa's Blog
by
kiyokawa
Method 1: Use the URL helper$url = $this->Url->build([ "controller" => "Posts", "action" => "search", "?" => ["foo" => "bar"] ],true);Method 2: Use the Routeruse Cake\Routing\Router;$url = Router::url([ 'controller' => 'Posts', 'action' => 'search', '?' => ['foo' => $bar] ], true);
-
投稿日 2019-06-02 12:45
kiyokawa's Blog
by
kiyokawa
Here is a handy way to do it:To check by primary key:if ($this->Users->exists($id)) {}To find by specifying where clause:if ($this->Users->exists(['email' => $email])) {}Much more convenient than using find('count').