6月
24日,
2019年
Yuki
on my wife's pillow.
6月
14日,
2019年
Japanese melon: Ibara King
The name Ibara King is a pun on the prefecture name Ibaraki. Sorry name but the fruit is delicious, it is sweet and has a nice solid texture. The Higo Green I had the other day was softer, more fragrant.
I give this one three stars too.
6月
13日,
2019年
Japanese melon: Higo Green
I like green ones best - here is a picture of Higo Green, a melon farmed in Kumamoto. It was yummy, I give it three stars.
6月
13日,
2019年
CakePHP3: Two sets of pagination for the same model
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' => 'current_articles',
],
'PastArticles' => [
'scope' => 'past_articles',
],
];
TableRegistry::config('PastArticles', [
'className' => 'App\Model\Table\ArticlesTable',
'table' => 'articles',
'entityClass' => 'App\Model\Entity\Article',
]);
$currentArticles = $this->paginate(
$this->Articles->find('all', [
'scope' => 'current_articles'
])->where(['expiry >' => Time::now()])
);
$pastArticles = $this->paginate(
TableRegistry::getTableLocator()->get('PastArticles')->find('all', [
'scope' => 'past_articles'
])->where(['expiry Time::now()])
);
$this->set(compact('currentArticles','pastArticles'));
And in your view, do this:
$this->Paginator->options(['model' => 'Articles']);
echo $this->Paginator->first('Paginator->prev('Paginator->numbers();
echo $this->Paginator->next('>');
echo $this->Paginator->last('>>');
$this->Paginator->options(['model' => 'PastArticles']);
echo $this->Paginator->first('Paginator->prev('Paginator->numbers();
echo $this->Paginator->next('>');
echo $this->Paginator->last('>>');
6月
9日,
2019年
CakePHP3: Check if user browsing from iPad
<?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/
6月
7日,
2019年
CakePHP3: Fetch a particular column from all rows
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();
6月
5日,
2019年
CakePHP3: Get the full URL of the current page
$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);
6月
2日,
2019年
CakePHP3: Check if record exists
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').
5月
31日,
2019年
Bash: working with filenames containing spaces
for i in `find . -type f`
do
cp "${i}" "${i}.bak"
done
This fails when filenames contain spaces, as bash uses whitespace, tab and LF as the default delimiter. Solution? Do this:
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")