嗨大家我正在研究一个基于MVC的php应用程序。在我的include.php中,它也在我服务器的服务器根目录中有以下代码,以便从应用程序目录中的Controller文件夹中自动获取模型和控制器。服务器根目录。
我的项目目录是这样的
accountBook
|-Application
| |-Controller
| | |-IndexController.php
| | |-baseController.php
| |_-Model
|-Content
|-index.php
|-config.php
|-includes.php
<?php
/*
*@Package Name: accountBook/includes.php
*@Date(Last Modified): Thru, Sept 15 - 2016
*@Author: Ajax Hill
*/
namespace accountBook
{
use accountBook\Application\Controller;
class accessControl
{
private $args,$type,$nature;
private static function route()
{
define('DS',DIRECTORY_SEPARATOR);
define('ROOT',getcwd().DS);
define('CONF', ROOT.'config.php');
include_once(CONF);
$con= new PDO;
if($result=$con->query('SELECT theme from sys_def'))
{
while($row=$result->fetch(PDO::FETCH_ASSOC))
{
define('THEME_NAME',$row['theme']);
}
}
else
{
echo "ERROR: Could not execute".print_r($pdo->errorInfo());
}
/*
* @var THEME_NAME(view) has been Fetch from Database
*/
define('CONTENT', ROOT.'content'.DS);
define('THEME_PATH',CONTENT.'themes'.DS.THEME_NAME.DS);
define('APP',ROOT.'Application'.DS);
define('CONTROL_PATH',APP.'contollers'.DS);
define('MODEL_PATH',APP.'models'.DS);
// index.php?p=admin&c=Goods&a=add
define("PLATFORM", isset($_REQUEST['p']) ? $_REQUEST['p'] : 'home');
define("CONTROLLER", isset($_REQUEST['c']) ? $_REQUEST['c'] : 'Index');
define("ACTION", isset($_REQUEST['a']) ? $_REQUEST['a'] : 'index');
unset($con);
}
// Autoloading
private static function autoload()
{
// Controller
require_once CONTROL_PATH. "{$classname}.php";
}
elseif (substr($classname, -5) == "Model")
{
// Model
require_once MODEL_PATH . "{$classname}.php";
}
}
// Routing and dispatching
private static function dispatch()
{
// Instantiate the controller class and call its action method
$controller_name = CONTROLLER . "Controller";
$action_name = ACTION . "Action";
$controller = new $controller_name;
$controller->$action_name();
}
public function __construct($type, $args,$nature='show')
/**
* var @type has two values = account | toDo
* var @type is post title
* var @nature is to determine the nature
*/
{
$this->args=$args;
$this->type=$type;
$this->nature=$nature;
self::route();
self::autoload();
self::dispatch();
}
}
}
现在我在Application文件夹
中创建了IndexController.php
<?php
/**
*@Package Name: accountBook/Application/Controller/IndexController.php
*@Date(Last Modified): Thru, Sept 15 - 2016
*@Author: Ajax Hill
*/
namespace accountBook\Application\controller;
class IndexController extends baseController
{
public function mainAction(){
include THEME_PATH. "main.html";
// Load Captcha class
$this->loader->library("Captcha");
$captcha = new Captcha;
$captcha->hello();
$userModel = new UserModel("user");
$users = $userModel->getUsers();
}
public function indexAction(){
$userModel = new UserModel("user");
$users = $userModel->getUsers();
// Load View template
include THEME_PATH . "index.php";
}
public function menuAction(){
include THEME_PATH . "menu.php";
}
public function dragAction(){
include THEME_PATH . "drag.php";
}
public function topAction(){
include THEME_PATH . "top.php";
}
}
fetal error at line 67 not found path c://phpproj/accountBook/Application/Controller/accountBook/Application/Controller/baseController.php
现在请帮我调整一下,以便从c://phpproj/accountBook/Application/Controller/baseController.php获取baseController
答案 0 :(得分:0)
你的班级应该读过如下内容:
<?php
/*
*@Package Name: accountBook/includes.php
*@Date(Last Modified): Thru, Sept 15 - 2016
*@Author: Ajax Hill
*/
namespace accountBook;
use accountBook\Application\Controller;
class accessControl {
private $args,$type,$nature;
private static function route(){
define('DS',DIRECTORY_SEPARATOR);
define('ROOT',getcwd().DS);
define('CONF', ROOT.'config.php');
include_once(CONF);
$con= new PDO;
if($result=$con->query('SELECT theme from sys_def')) {
while($row=$result->fetch(PDO::FETCH_ASSOC)){
define('THEME_NAME',$row['theme']);
}
}else{
echo "ERROR: Could not execute".print_r($pdo->errorInfo());
}
/*
* @var THEME_NAME(view) has been Fetch from Database
*/
define('CONTENT', ROOT.'content'.DS);
define('THEME_PATH',CONTENT.'themes'.DS.THEME_NAME.DS);
define('APP',ROOT.'Application'.DS);
define('CONTROL_PATH',APP.'contollers'.DS);
define('MODEL_PATH',APP.'models'.DS);
// index.php?p=admin&c=Goods&a=add
define("PLATFORM", isset($_REQUEST['p']) ? $_REQUEST['p'] : 'home');
define("CONTROLLER", isset($_REQUEST['c']) ? $_REQUEST['c'] : 'Index');
define("ACTION", isset($_REQUEST['a']) ? $_REQUEST['a'] : 'index');
unset($con);
}
// Autoloading
private static function autoload(){
$classname = algorithm_2_get_className();
if(substr($classname, -10) == "Controller"){
// Controller
$classFile = CONTROL_PATH . "{$classname}.php";
}else if (substr($classname, -5) == "Model"){
// Model
$classFile = MODEL_PATH . "{$classname}.php";
}
if(file_exists($classFile){
require_once $classFile;
}else{
// HANDLE FILE-NOT FOUND EXCEPTION...
}
}
// Routing and dispatching
private static function dispatch(){
// Instantiate the controller class and call its action method
$controller_name = CONTROLLER . "Controller";
$action_name = ACTION . "Action";
$controller = new $controller_name;
$controller->$action_name();
}
public function __construct($type, $args,$nature='show'){
/**
* var @type has two values = account | toDo
* var @type is post title
* var @nature is to determine the nature
*/
$this->args=$args;
$this->type=$type;
$this->nature=$nature;
self::route();
self::autoload();
self::dispatch();
}
}