【问题标题】:CakePHP cacheHelper - appController not found errorCakePHP cacheHelper - appController not found 错误
【发布时间】:2012-12-24 07:58:08
【问题描述】:

我将 CacheHelper 添加到我的应用程序中。 在我的 APP/Config/core.php 我有

Configure::write('Cache.check', true);

在 APP/Config/bootstrap.php 我有

Configure::write('Dispatcher.filters', array(
  'AssetDispatcher',
  'CacheDispatcher'
));

在我的控制器中,我有:

public $helpers = array('Text', 'Cache');
public $cacheAction = "1 hour";

我在这个控制器和 AppController 中都没有直接的回调。 问题是每个页面只加载一次(例如——在缓存被清除之后)。应第二个要求,我会回来

Fatal Error

Error: Class 'AppController' not found  

如果缓存关闭,一切正常。

CakePHP 版本为 2.2.3

调试日志:

 2012-12-24 12:21:00 Error: Fatal Error (1): Class 'AppController' not found in    [/Volumes/../app/Controller/NewsController.php, line 2]
 2012-12-24 12:21:00 Error: [FatalErrorException] Class 'AppController' not found
 #0 /Volumes/../lib/Cake/Error/ErrorHandler.php(161): ErrorHandler::handleFatalError(1,     'Class 'AppContr...', '/Volumes/Data/D...', 2)
 #1 [internal function]: ErrorHandler::handleError(1, 'Class 'AppContr...', '/Volumes/../D...', 2, Array)
 #2 /Volumes/../lib/Cake/Core/App.php(926): call_user_func('ErrorHandler::h...', 1, 'Class 'AppContr...', '/Volumes/../D...', 2, Array)
 #3 /Volumes/../lib/Cake/Core/App.php(899): App::_checkFatalError()
 #4 [internal function]: App::shutdown()
 #5 {main}

NewsController:

<?php
class NewsController extends AppController {
public $components = array('Security', 'ImageTool', 'Uploader');
public $paginate = array(
        'fields' => array('News.id', 'News.created'),
        'limit' => 5,
        'contain' => array(),
        'order' => array('News.id' => 'DESC'));

public $helpers = array('Text', 'Cache');
public $cacheAction = "1 hour";

【问题讨论】:

  • 您的错误/调试日志是否添加了任何其他信息?或者这就是您遇到的所有错误反馈?
  • 当我注意到第一个结果时,我正在用 https://www.google.nl/search?q=cakephp+cache+appcontroller+not+found 搜索它。看起来 SO 被抓取得非常非常快:)
  • 我已经更新了我的问题
  • 我想我可以猜到line 2 of the NewsController 上会发生什么,但是您能否也将这行代码(+ 和 - 几行?)添加到您的问题中?也许这里出了点问题。我不知道,但让我们检查一下:)
  • 再一次 - 问题已更新。提前致谢。

标签: php cakephp caching


【解决方案1】:

获胜者是... App::uses('AppController', '控制器');在控制器代码的顶部。

App::uses('AppController', 'Controller');

class NewsController extends AppController {
public $helpers = array('Cache');
public $cacheAction = array(
    'index'  => 48000
);

public function index() {

}
public function clear() {
    clearCache();
}
}

我不知道为什么这还没有包含在食谱中。

【讨论】:

  • 哈哈是认真的吗? “使用” AppController 有点重要。例如,它在 PagesController 中;)
  • 是的。但我没有在食谱中找到有关它的信息。我一直认为 App::uses('AppController', 'Controller');在 AppController.php 中就足够了。
  • 这很奇怪,它不在食谱中并且没有调试,蛋糕崩溃。非常感谢!
  • 我不明白这个错误背后的原因。谁能解释一下为什么我们使用缓存助手时会发生这种情况?
【解决方案2】:
<?php
namespace App\Controller;
use App\Controller\AppController;
class StudentsController extends AppController{}

这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-28
    • 2013-02-20
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多