此自定义路由类可以工作,但是当我用自定义查找器替换查询时,它会返回错误:未知的查找器方法"已发布"。是不是可以在这里使用自定义查找器?
class ContentsRoute extends Route {
public function parse($url) {
$params = parent::parse($url);
if (!($params)) {
return false;
}
$pages = Cache::read('pages');
if ($pages === false) {
$contents = TableRegistry::get('Contents');
// custom finder
// $query = $contents->find('published');
$query = $contents->find()
->select(['id', 'path', 'public'])
->where(['Contents.published' => 1]);
$pages = $query->toArray();
Cache::write('pages', $pages);
}
if (isset($pages[$url])) {
$params['pass'] = array('path' => $url);
return $params;
}
return false;
}
}
//ContentsTable.php
public function findPublished(Query $query, array $options)
{
$query = $this->find()
->select(['id', 'path', 'public'])
->where(['Contents.published' => 1]);
return $query;
}