本文整理匯總了PHP中CFactory::instance方法的典型用法代碼示例。如果您正苦於以下問題:PHP CFactory::instance方法的具體用法?PHP CFactory::instance怎麽用?PHP CFactory::instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CFactory
的用法示例。
在下文中一共展示了CFactory::instance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
function run()
{
try {
$this->_filter->routeStartup();
//路由開始
$action = $this->_router->route();
$action = $this->_filter->routeShutdown($action);
//路由關閉
$action = $this->_filter->dispatchStartup($action);
//方法調度
$method = $action->_method;
$action->{$method}();
$this->_filter->dispatchShutdown();
//方法調度完成
$action->response();
$this->_filter->endReturn();
//返回結果
} catch (CException $e) {
//異常處理
if ($e->exceptionType == 'biz') {
//業務邏輯異常--拋到業務層處理
$actionclass = $e->exActionMethod . '_Action';
$action = CFactory::instance($actionclass, $e->params, true, true);
$method = $action->_method;
$action->{$method}();
$action->response();
$this->_filter->endReturn();
//返回結果
} else {
//核心異常--直接拋出異常
throw new Exception($e);
}
}
}
示例2: route
function route($controller = null, $action = null, $method = null)
{
if (!$controller && !$action) {
$paths = $this->_url_path->getRequestPaths();
if (sizeof($paths) <= 1) {
if ($paths[0] == '') {
$controller = 'index';
$action = 'index';
} else {
if (substr($paths[0], 0, 1) == '~') {
$controller = 'index';
$action = 'index';
} else {
$controller = $paths[0];
$action = 'index';
}
}
} else {
$start = 0;
if (substr($paths[$start], 0, 1) == '~') {
$controller = 'index';
$action = 'index';
$method = substr($paths[$start], 1);
$start += 1;
} elseif (substr($paths[$start + 1], 0, 1) == '~') {
$controller = $paths[$start];
$action = 'index';
$method = substr($paths[$start + 1], 1);
$start += 2;
} elseif (isset($paths[$start + 2]) && substr($paths[$start + 2], 0, 1) == '~') {
$controller = $paths[$start];
$action = $paths[$start + 1];
$method = substr($paths[$start + 2], 1);
$start += 3;
} else {
$controller = $paths[$start];
$action = $paths[$start + 1];
$start += 2;
}
}
}
$actionName = $controller . '_' . $action . '_Action';
$action = CFactory::instance($actionName, array(), true, false);
if (isset($method)) {
$action->_method = $method;
}
$action->_actionName = $actionName;
return $action;
}