本文整理匯總了PHP中Dispatcher::setController方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::setController方法的具體用法?PHP Dispatcher::setController怎麽用?PHP Dispatcher::setController使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setController方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAjaxTemplate
private function getAjaxTemplate()
{
foreach ($this->vars->isPost() as $key => $value) {
$data[$key] = $value;
}
$dispatcher = new Dispatcher();
$controller = $dispatcher->setController($data);
// Assign variables for the template
if ($controller['vars']) {
foreach ($controller['vars'] as $key => $value) {
$this->smarty->assign($key, $value);
}
}
if (isset($data['response'])) {
if ($data['response'] == 'html') {
return array('response' => 'html', 'data' => $dispatcher->loadTemplate());
} elseif ($data['response'] == 'json') {
return array('response' => 'json', 'data' => json_encode($controller['vars']));
} else {
throw new Exception('Ajax dataType must be html or json');
}
} else {
throw new Exception('response data must be given');
}
}
示例2: die
die('Unable to connect to database.');
}
$objAuthentication = Authentication::getInstance();
$objSettings = Settings::getInstance();
$objDispatcher = new Dispatcher();
// custom url rewriting
$objUrls = new FriendlyurlModel();
$objUrls->parseRequest($params['_urlrequest']);
if (!empty($objUrls->requestParams)) {
$params = array_merge($params, $objUrls->requestParams);
}
// start up
try {
$objSettings->loadSettings();
$objDispatcher->setDirectory('frontend');
$objDispatcher->setController($objUrls->requestController);
$objDispatcher->setAction($objUrls->requestAction);
$objDispatcher->setParams($params);
$objDispatcher->dispatch();
} catch (Exception $e) {
$objEmail = new Emailer();
$objEmail->addTO(ERROR_EMAIL);
$objEmail->setFrom(ERROR_EMAIL);
$objEmail->setSubject('FATAL ERROR | Exception thrown on ' . URL);
$objEmail->setBody('Fatal Exception! ' . $e->getMessage() . print_r($params, true));
//$objEmail->sendMail();
die('Error<br/>' . $e->getMessage() . '<br/><a href="http://' . URL . '">' . PRODUCT_NAME . '</a>');
}
// time to clean up
$dbQueries = $objDatabase->getNumbQueries();
$objDatabase->disconnect();
示例3: ucfirst
} else {
$action = ucfirst(!empty($params['_action']) ? $params['_action'] : 'Index');
}
}
// permission check
$objPermissions = Permissions::getInstance();
$hasPermission = $objPermissions->actionAllowed($controller, $action, $objAuthentication->user_id);
if (!$hasPermission) {
$controller = 'Error';
$action = 'Permission';
}
// start up
try {
$objSettings->loadSettings();
$objDispatcher->setDirectory('backend');
$objDispatcher->setController($controller);
$objDispatcher->setAction($action);
$objDispatcher->setParams($params);
$objDispatcher->dispatch();
} catch (Exception $e) {
$objEmail = new Emailer();
$objEmail->addTO(ERROR_EMAIL);
$objEmail->setFrom(ERROR_EMAIL);
$objEmail->setSubject('FATAL ERROR | Exception thrown on ' . URL);
$objEmail->setBody('Fatal Exception! ' . $e->getMessage());
$objEmail->sendMail();
die('Error<br/>' . $e->getMessage() . '<br/><a href="http://' . URL . '">' . PRODUCT_NAME . '</a>');
}
// time to clean up
$dbQueries = $objDatabase->getNumbQueries();
$objDatabase->disconnect();
示例4: actionNewReply
function actionNewReply($params = '')
{
if ($this->objAuthentication->loggedIn()) {
if (!empty($params['newPost']) && $params['newPost'] == 1) {
$forumModel = new ForumModel();
if (!$forumModel->isThreadLocked($params['threadId'])) {
$post = array();
$post['postid'] = $params['threadId'];
$post['topic'] = $params['topic'];
$post['message'] = $params['message'];
$newPost = $forumModel->addReply($post);
if ($newPost) {
$objSettings = Settings::getInstance();
$perPage = $objSettings->getEntry('per_page_posts');
$thread = $forumModel->getThread($post['postid']);
$category = $forumModel->getCategory($thread['topic']['catid']);
$channel = $forumModel->getChannel($category['channelid']);
$totalPages = ceil($forumModel->numbReplies($thread['topic']['id']) / $perPage);
if ($totalPages == 0) {
$totalPages = 1;
}
header("Location: http://" . URL . "/community/" . preg_replace('/[^a-zA-Z]/', '_', $channel['name']) . "-" . $channel['id'] . "/" . preg_replace('/[^a-zA-Z]/', '_', $category['name']) . "-" . $category['id'] . "/" . preg_replace('/[^a-zA-Z]/', '_', $thread['topic']['topic']) . "-" . $thread['topic']['id'] . "-" . $totalPages . ".html#" . $newPost);
}
} else {
$this->view->assign('content', 'This thread is locked');
$this->finish();
}
} else {
$objDispatcher = new Dispatcher();
$objDispatcher->setController('Forum');
$objDispatcher->setAction('Index');
$objDispatcher->setParams($params);
$objDispatcher->dispatch();
}
} else {
$this->view->assign('errorMsg', 'You must login to make a post');
$this->view->assign('content', $this->view->fetch('tpl/community/login.tpl'));
$this->finish();
}
}
示例5: actionSubmit
function actionSubmit($params2 = '')
{
// loading $params from global so that the View can load the proper _urlrequest
global $params;
$params = array_merge($params, $params2);
$hasError = false;
$formErrors = array();
if (!empty($params['formSubmit'])) {
$objEmail = new EmailSender();
$objForm = new FormModel();
if (!empty($params['formSubmit']['id'])) {
$formInfo = $objForm->loadForm($params['formSubmit']['id']);
// validate forms fields
if (!empty($formInfo['fields'])) {
foreach ($formInfo['fields'] as $formField) {
if ($formField['required'] == 1) {
if (empty($params['formSubmit']['fields'][$formField['id']])) {
$hasError = true;
$formError = array('field_id' => $formField['id'], 'errorMsg' => $formField['name'] . ' is required.');
$formErrors[] = $formError;
}
}
}
}
if ($hasError) {
// return to page with error message
if (!empty($params['returnUrlRequest']) && $params['returnUrlRequest'] != 'Form/submit') {
$objDispatcher = new Dispatcher();
$objFriendlyUrl = new FriendlyurlModel();
$objFriendlyUrl->parseRequest($params['returnUrlRequest']);
$controller = $objFriendlyUrl->requestController;
$action = $objFriendlyUrl->requestAction;
$params = array_merge($params, $objFriendlyUrl->requestParams);
$params['_urlrequest'] = $params['returnUrlRequest'];
$params['formErrors'] = $formErrors;
$objDispatcher->setDirectory('frontend');
$objDispatcher->setController($controller);
$objDispatcher->setAction($action);
$objDispatcher->setParams($params);
$objDispatcher->dispatch();
exit;
} else {
die('Please go back and retry submitting the form. Errors: ' . print_r($formErrors));
}
}
// save to database
$submission_id = $this->saveToDb($params);
if ($submission_id) {
$params['submission_id'] = $submission_id;
}
// email notification
$objEmail->sendForm($params);
// return to page with thanks message
if (!empty($params['returnUrlRequest'])) {
header("Location: http://" . URL . '/' . $params['returnUrlRequest'] . '?formSubmitted=true');
} else {
header("Location: http://" . URL . '/');
}
}
}
}