php - 我无法解决“缺少控制器错误”
问题描述
我应该制作正确的名称控制器,但缺少控制器错误不会消失。
我正在从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。在以下文件中创建 ArticleController 类:src/Controller/ArticleController.php
解决方案
可以在此处找到该教程的完整源代码。 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);
}
推荐阅读
- ios - 提供实体计数的 NSFetchedResultsController 对象
- xunit.net - dotnet test > 有没有办法显示在控制台中运行的测试列表?
- amazon-web-services - AWS ECS 服务定义:角色属性
- python - 列表索引超出范围,但该项目存在
- javascript - 如何用 Konva 连续绘制分割多边形?
- html - 每个不同的多个文本行分别影响放置在多个文本上方的图像的位置
- sql-server - 如何在 sql server2012 中将 datetime 转换为 int?
- python - 如何使用 python (ucrtbase.DLL) 解析 ucrtbase.dll APPCRASH
- java - 如何在 java 中使用 ews 从电子邮件中获取“收件人”信息
- ruby - Fluent D record_transformer 插件和 Ruby,最终与 elasticsearch、Kibana 一起使用