我正在做蛋糕讲解,一旦结束,我正在查看文章编辑页面内的Debugkit sql日志,看起来由于某种原因重复了检索文章数据的查询。
这是两次显示的查询:
SELECT
Articles.id AS `Articles__id`,
Articles.user_id AS `Articles__user_id`,
Articles.title AS `Articles__title`,
Articles.slug AS `Articles__slug`,
Articles.body AS `Articles__body`,
Articles.published AS `Articles__published`,
Articles.created AS `Articles__created`,
Articles.modified AS `Articles__modified`
FROM
articles Articles
WHERE
Articles.slug = 'first-post'
LIMIT
1
这是编辑功能:
public function edit($slug)
{
$article = $this->Articles
->findBySlug($slug)
->contain('Tags') // load associated Tags
->firstOrFail();
if ($this->request->is(['post', 'put'])) {
$this->Articles->patchEntity($article, $this->request->getData(), [
// Added: Disable modification of user_id.
'accessibleFields' => ['user_id' => false]
]);
if ($this->Articles->save($article)) {
$this->Flash->success(__('Your article has been updated.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Unable to update your article.'));
}
$tags = $this->Articles->Tags->find('list');
$this->set('article', $article);
$this->set('tags', $tags);
}
该查询仅应在此行执行一次:
$article = $this->Articles
->findBySlug($slug)
->contain('Tags') // load associated Tags
->firstOrFail();
正确吗?
答案 0 :(得分:0)
有可能,调试工具加载了两次。请参阅bootstrap.php配置文件。如果有,请删除它,因为在3.6中正在Application.php中加载