現在
パーフェクトPHPを通して、
PHPを学んでいます。
そこで、
7章で、フレームワークの土台を作成しました。
miniblogというディレクトリの配下に、
core , web , models , controllers , viewsというディレクトリがあります。
8章では実際にミニブログの実装を行うのですが、
その際に、miniblogディレクトリ配下に、MiniBlogApplication.phpファイルを作成し、そのファイルに、coreのApplication.phpファイルの内容をextendsさせるというのがありました。
MiniBlogApplication.phpのソースコードはこれです。
<?php class MiniBlogApplication extends Application { protected $login_action = array('account' , 'signin'); public function getRootDir() { return dirname(__FILE__); } protected function registerRoutes() { return array( ); } protected function configure() { $this->db_manager->connect( 'master' , array( 'dsn' => 'mysql:dbname=mini_blog;host=localhost', 'user' => 'root', 'password' => '', ) ); } }
そのMiniBlogApplication.phpファイルを、webディレクトリ配下のindex.phpでrequireして使用するということでrequireしてみた結果、
Fatal error: Class 'Application' not found in /Applications/XAMPP/xamppfiles/htdocs/mini-blog.localhost/MiniBlogApplication.php on line 5
このようなエラーが発生しました。
そのため、
パーフェクトPHPのサンプルコード確認して、デバックし、再度index.phpを開いてみましたが、このエラーが消えません。
どなたか解決方法を教えていただけないでしょうか?
よろしくお願いします。
ちなみに、
miniblog/Core/Application.phpのソースコードはこれです。
<?php abstract class Application { protected $debug = false; protected $request; protected $response; protected $session; protected $db_manager; protected $login_action = array(); public function __construct($debug = false ) { $this->setDebugMode($debug); $this->initialize(); $this->configure(); } protected function setDebugMode($debug) { if ( $debug){ $this->debug = true; ini_set('display_errors' , 1 ); error_reporting(-1); } else { $this->debug = false; ini_set( 'display_errors' , 0 ); } } protected function initialize() { $this->request = new Request(); $this->response = new Response(); $this->session = new Session(); $this->db_manager = new DbManager(); $this->router = new Router ( $this->registerRoutes() ); } protected function configure() { } abstract public function getRootDir(); abstract protected function registerRoutes(); public function isDebugMode() { return $this->debug; } public function getRequest() { return $this->request; } public function gerResponse() { return $this->response; } public function getSession() { return $this->session; } public function getDbManager() { return $this->db_manager; } public function getControllerDir() { return $this->getRootDir() . '/controllers'; } public function getViewDir() { return $this->getRootDir() . '/views'; } public function getModelDir() { return $this->getRootDir() . '/models'; } public function getWebDir() { return $this->getRootDir() . '/web'; } public function run() { try{ $params = $this->router->resolve($this->request->getPathInfo() ); if ( $params === false){ throw new HttpNotFoundException( 'No route found for ' . $this->request->getPathInfo() ); } $controller = $params['controller']; $action = $params['action']; $this->runAction($controller,$action,$params); }catch (HttpNotFoundException $e){ $this->render404Page($e); } catch (UnauthorizedActionException $e){ list($controller , $action) = $this->login_action; $this->runAction($controller, $action); } $this->response->send(); } public function runAction($controller_name , $action , $params = array() ) { $controller_class = ucfirst($controller_name) . 'Controller'; $controller = $this->findController($controller_class); if ($controller === false){ throw new HttpNotFoundException( $controller_class . ' controller is not found . ' ); } $content = $controller->run($action , $params); $this->response->setContent($content); } protected function findController($controller_class) { if ( !class_exists($controller_class) ){ $controller_file = $this->getControllerDir() . '/' . $controller_class . '.php'; if ( !is_readable($controller_file) ){ return false; } else { require_once $controller_file; if ( !class_exists($controller_class) ){ return false; } } } return new $controller_class($this); } protected function render404Page($e) { $this->response->setStatusCode(404 , 'Not Found'); $message = $this->isDebugMode() ? $e->getMessage() : 'Page not found.'; $message = htmlspecialchars($message , ENT_QUOTES, 'UTF-8'); $this->response->setContent( <<<EOF <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>404</title> </head> <body> {$message} </body> </html> EOF ); } }
回答7件
あなたの回答
tips
プレビュー