我是 Phalcon 的新手并试图访问控制器中的模型,但显示以下错误:
Fatal error: Uncaught Error: Class 'settings\Settings' not found in C:\xampp\htdocs\icriticize\app\controllers\UserEndController.php:11 Stack trace: #0 [internal function]: UserEndController->homeAction() #1 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(UserEndController), 'homeAction', Array) #2 [internal function]: Phalcon\Dispatcher->dispatch() #3 C:\xampp\htdocs\icriticize\public\index.php(42): Phalcon\Mvc\Application->handle() #4 C:\xampp\htdocs\icriticize\.htrouter.php(30): require_once('C:\\xampp\\htdocs...') #5 {main} thrown in C:\xampp\htdocs\icriticize\app\controllers\UserEndController.php on line 11
值得一提的是,我使用 Phalcon-dev-tools 创建了这个项目,我正在使用 phalcon serve 命令运行它。
这是控制器:
<?php
use \settings\Settings;
class UserEndController extends \Phalcon\Mvc\Controller
{
public function homeAction()
{
$settings = Settings::findFirst(1);
}
}
这是loader.php文件:
<?php
$loader = new \Phalcon\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(
[
$config->application->controllersDir,
$config->application->modelsDir
]
)->register();
这是config.php文件:
<?php
/*
* Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
* NOTE: please remove this comment.
*/
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
return new \Phalcon\Config([
'database' => [
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'icriticize',
'charset' => 'utf8',
],
]);