-
posted 2019-06-12 10: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' => [ 'scope' => 'cu...
-
posted 2019-06-10 11:38
kiyokawa's Blog
by
kiyokawa
cd app/bin ./cake cache clear_all
-
posted 2019-06-08 21:03
kiyokawa's Blog
by
kiyokawa
Cake is built in with MobileDetect nowadays, so it is as simple as this: <?php use Mobile_Detect; $mb = new Mobile_Detect; if($mb->isIpad()){ echo "is ipad"; }else{ echo "is not ipad"; } There are other handy methods such is isMobile(), isChrome() etc: http://mobiledetect.net/
-
posted 2019-06-06 20:55
kiyokawa's Blog
by
kiyokawa
Say we have the following data in a table called countries: id country capitol 1 USA Washington DC 2 Japan Tokyo 3 United Kingdom London And you want to fetch data like this: ['Washington DC', 'Tokyo', 'London'] Then do this: $capitols = $this->countries ->find() ->extract('capitol') ->toArray();
-
posted 2019-06-04 20: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 Router use Cake\Routing\Router; $url = Router::url([ 'controller' => 'Posts', 'action' => 'search', '?' => ['foo' => $bar] ], true);
-
posted 2019-06-01 20: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').