我应该做一个正确的名字控制器, 但缺少控制器错误不会消失。
我正在从https://book.cakephp.org/3.0/en/tutorials-and-examples/cms/articles-controller.html
开始做CakePHP教程它在/ kaede / code / cake / cms / src / Controller中
<?php
namespace App\Controller;
use App\Controller\AppController;
class ArticlesController extends AppController {
public function index() {
$this->loadComponent('Paginator');
$articles = $this->Paginator->paginate($this->Articles->find());
$this->set(compact('articles'));
}
public function edit() {
$article = $this->Articles->findBySlug($slug)->firstOrFail();
if ($this->request->is(['post', 'put'])) {
$this->Articles->patchEntity($article, $this->request->getData());
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.'));
}
$this->set('article', $article);
}
}
缺少控制器 找不到ArticleController。 在文件src / Controller / ArticleController.php
中创建以下类ArticleController。答案 0 :(得分:0)
可以在此处找到该教程的完整源代码。 https://github.com/cakephp/cms-tutorial/blob/master/src/Controller/ArticlesController.php
仔细检查文章和文章的拼写,可能是这样。
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.'));
}
// Get a list of tags.
$tags = $this->Articles->Tags->find('list');
// Set article & tags to the view context
$this->set('tags', $tags);
$this->set('article', $article);
}
答案 1 :(得分:0)
类名是singler。
class ArticlesController extends AppController {