How to use different datasources in a Query using cakephp3?

For now, CakePHP doesn’t take datasource configurations into account when creating joins, and I don’t think that this will be added in the near future, not least because cross database joins aren’t supported “out of the box” (as in, just prepend the database name and you’re set) in Postgres and SQLite. Assuming you are using … Read more

How to setup cronjobs in cake php?

Use a shell The ‘Cake Way’ of using a CakePHP application in cron jobs would be creating shell and then calling it as a cron job. i.e. Create a shell to do the task, and then add it to crontab (crontab -e on linux machine): 0 * * * * cd /path/to/app/ && Console/cake your_shell_name … Read more

How do I write a join query across multiple tables in CakePHP?

$markers = $this->Marker->find(‘all’, array(‘joins’ => array( array( ‘table’ => ‘markers_tags’, ‘alias’ => ‘MarkersTag’, ‘type’ => ‘inner’, ‘foreignKey’ => false, ‘conditions’=> array(‘MarkersTag.marker_id =’) ), array( ‘table’ => ‘tags’, ‘alias’ => ‘Tag’, ‘type’ => ‘inner’, ‘foreignKey’ => false, ‘conditions’=> array( ‘ = MarkersTag.tag_id’, ‘Tag.tag’ => explode(‘ ‘, $this->params[‘url’][‘q’]) ) ) ))); as referred to in nate … Read more

CakePHP 3.0 -> Between find condition

Expressions Between expression are supported out of the box, however they only support the first case without additional fiddling: $Query = $Table ->find() ->where(function($exp) { return $exp->between(‘start_date’, ‘2014-01-01’, ‘2014-12-32’, ‘date’); }); If you’d wanted to handle the second case via the between method, then you’d have to pass all values as expressions, which can easily … Read more

How to limit contained associations per record/group?

What you are looking for, is a solution to the greatest-n-per-group problem. You didn’t mention any specific RDBMS, but nonetheless see also A library solution For those who are a little bit adventurous, I’ve developed some custom associations that transparently integrate into the ORM layer, and allow for basic limit per group for hasMany … Read more

CakePHP 3.0 installation: intl extension missing from system

I faced the same problem today. You need to enable the intl PHP extension in your PHP configuration (.ini). Solution Xampp (Windows) Open /xampp/php/php.ini Change ;extension=php_intl.dll to extension=php_intl.dll (remove the semicolon) Copy all the /xampp/php/ic*.dll files to /xampp/apache/bin Restart apache in the Xampp control panel Solution Linux (thanks to Annamalai Somasundaram) Install the php5-intl extension … Read more

How to filter by conditions for associated models?

Use Query::matching() or Query::innerJoinWith() When querying from the Contacts table, then what you are looking for is Query::matching() or Query::innerJoinWith(), not (only) Query::contain(). Note that innerJoinWith() is usually preferred in order to avoid problems with strict grouping, as matching() will add the fields of the association to the select list, which can cause problems as … Read more