프레임 워크를 설정 한 것과 같은 작업이있었습니다. 이것은 나를위한 솔루션 작업입니다.
먼저 .htaccess 파일을 만듭니다. 재 작성 조건을 설정하고 템플릿 경로를 제외하십시오. 당신은 (단지 & 붙여 넣기 복사) 그런 식으로 작업을 수행 할 수 있습니다 내가 앞서 가기 전에
RewriteEngine On
Options +Indexes
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/index\.php -f
RewriteCond %{DOCUMENT_ROOT}/template -d
RewriteRule ^(.*)$ index\.php?$1 [QSA]
, 우리는 다섯 디렉토리 최소한 작성해야합니다 : 이제
/var/www/models/
/var/www/controllers/
/var/www/classes/
/var/www/system/
/var/www/template/
을, 나는에 자동 로딩을 추가 내 index.php :
<?php
error_reporting(E_ALL^E_NOTICE);
session_start();
function autoload($class_name)
{
$autoloadDirs = array('models', 'classes', 'controllers');
foreach($autoloadDirs as $dir)
{
if(file_exists($dir.'/'.$class_name.'.php'))
{
require_once($dir.'/'.$class_name.'.php');
}
}
}
spl_autoload_register('autoload');
require_once('system/Calling.php');
Calling::Run();
?>
위 스크립트에서 여러분은 호출 중 require_once를 볼 수 있습니다.
//-> Load the main controller with default action
www.example.com/
//-> Load the main controller with default action
www.example.com/main/default/
//-> Load the main controller with second action
www.example.com/main/second/
//-> Load the main controller with second action and gives two params
www.example.com/main/second/key1/value1/key2/value2/
: PHP는
class Calling
{
public static function Run($querystring = null)
{
//1. Parameter = Contollername
//2. Parameter = Action
$qString = preg_replace('/(\/$|^\/)/','',$querystring === null ? $_SERVER['QUERY_STRING'] : $querystring);
$callParam = !empty($qString) ? explode('/', $qString) : array();
$controllerName = count($callParam) > 0 ? (class_exists(ucfirst($callParam[0]).'Controller') ? ucfirst(array_shift($callParam)) : 'Error') : 'Main';
//All controllers have suffix "Controller" -> NameController.php
//and class name ike NameController
//If no controller name given, use MainController.php
$controllerClassName = $controllerName.'Controller';
//All public methods have suffix "Action" -> myMethodAction
//If there is no method named, use DefaultAction
$actionName = count($callParam) > 0 && method_exists($controllerClassName, ucfirst($callParam[0]).'Action') ? ucfirst(array_shift($callParam)) : 'Default';
$actionFunctionName = $actionName.'Action';
//Fetch the params
$param = new stdClass();
for($i = 0; $i < count($callParam); $i += 2)
{
$param->{$callParam[$i]} = isset($callParam[$i + 1]) ? $callParam[$i+1] : null;
}
////////////////////////////////////////////////////////////
//Init the Controller
$controller = new $controllerClassName($controllerName, $actionName);
$controller->$actionFunctionName($param);
////////////////////////////////////////////////////////////
//If you adapt this code: Is up to you to extends your controller
//from an internal controller which has the method Display();
$controller->Display();
}
}
또한, 컨트롤러 디렉토리에 당신이 그와 같은 컨트롤러, 방법 및 PARAMS를 호출 할 수 있습니다,
//--> just better if you have also an internal controller with your global stuff
//--> class MainController extends Controller
class MainController
{
/** This is the default action
* @param $params
* @access public
* @return
*/
public function DefaultAction(stdClass $params)
{
//-> Do your staff here
}
/** This is the second action
* @param $params
* @access public
* @return
*/
public function SecondAction(stdClass $params)
{
//-> Do your staff here
}
/** This is the view handling method which has to run at least
* and I recommend to set up an internal controller and to extend
* all other controller from it and include this method in your
* internal controller
* @param
* @access
* @return
*/
public function Display()
{
//-> Run your template here
}
?>
이제 첫 번째 컨트롤러 namend MainController.php를 추가 이제 자신 만의 프레임 워크를 시작하기 위해 다음 파일과 디렉토리를 갖게됩니다.
/var/www/.htaccess
/var/www/index.php
/var/www/controllers/MainController.php
/var/www/system/Calling.php
/var/www/models/
/var/www/classes/
/var/www/template/
는
이 유 젠드 프레임 워크 소스에서 찾고 시도 않은 새 기본 프레임 워크 키트 즐겨? – emaillenin
나는 zend 프레임 워크에서 어떻게 수행되고 있는지 이해할 수 없었다. – Justin