本文整理汇总了PHP中Router::set404方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::set404方法的具体用法?PHP Router::set404怎么用?PHP Router::set404使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::set404方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _run_
public function _run_($param = null)
{
if (is_null($param)) {
if (method_exists($this, '_absent_')) {
$this->_absent_();
} else {
Router::set404();
}
return;
}
if (method_exists($this, '_always_')) {
if ($this->_always_() === false) {
return;
}
}
if ($param === '') {
if (method_exists($this, '_empty_')) {
$this->_empty_();
} else {
Router::set404();
}
} elseif (mb_substr($param, 0, 1) !== '_' && method_exists($this, $param)) {
$rm = new ReflectionMethod($this, $param);
if ($rm->isPublic()) {
$this->{$param}();
} else {
Router::set404();
}
} else {
Router::set404();
}
}
示例2: getUrlSegment
public static function getUrlSegment($part, $required = true, $pattern = '/^[-a-z0-9_]+$/i')
{
try {
return self::getFromArr(self::$url_segments, $part, $required, $pattern, '');
} catch (ValidatorException $e) {
Router::set404();
}
}
示例3: file
public static function file($path, $data = null)
{
try {
FileSys::includeFile($path, $data);
} catch (SystemException $e) {
Router::set404();
}
}
示例4: start
public static function start()
{
//если сайт отключен
if (SConfig::SITE_DISABLED) {
FileSys::includeFile(SITE_ROOT . '/client/pages/site_disabled.php');
exit;
}
//в переменную $request_url заносим url без GET-параметров
$request_url = explode('?', $_SERVER['REQUEST_URI'])[0];
//проверяем url
if (!preg_match('/^\\/(([-a-z0-9_]+\\/)*[-a-z0-9_]+\\.html)?(\\?.*)?$/', $request_url)) {
Router::set404();
}
Request::setOriginalUrl($request_url);
$db = (new Db())->setTable('url_redirects');
//если у страницы есть новый адрес - перенаправляем, чтобы избежать дублей страниц
if ($ou = $db->getOne('SELECT `old_url` FROM # WHERE new_url=?s AND type="I"', $request_url)) {
Router::redirect($ou);
}
//проверяем, есть ли редиректы
$r = $db->getRow('SELECT `new_url`,`type`,`comment` FROM # WHERE old_url=?s', $request_url);
if ($r) {
//если редирект внутренний
if ($r[1] === 'I') {
$request_url = $r[0];
} elseif ($r[1] === 'E') {
Router::redirect($r[0]);
}
}
//получаем параметры пункта меню (если есть)
$item = $db->getRow('SELECT * FROM ##menu_items WHERE `item_url`=?s', [Request::getOriginalUrl()], MYSQLI_ASSOC);
if ($item) {
if ($item['params']) {
$item['params'] = Json::decode($item['params']);
}
Request::setItemParams($item);
}
Request::setRealUrl($request_url);
Request::setUrlSegments(explode('/', substr($request_url, 1, -5)));
//запускаем вывод страницы
Document::generate();
}
示例5: generateComponent
public static function generateComponent()
{
$com_name = Request::getUrlSegment(0);
//проверяем наличие такого компонента
if (!is_dir(SITE_ROOT . '/components/' . $com_name)) {
Router::set404();
}
ob_start();
//запускаем работу компонента
if (is_file(SITE_ROOT . '/components/' . $com_name . '/index.php')) {
Load::file(SITE_ROOT . '/components/' . $com_name . '/index.php');
} else {
$section = Request::getUrlSegment(1);
if (is_file(SITE_ROOT . '/components/' . $com_name . '/' . $section . '/' . $section . '.php')) {
Load::file(SITE_ROOT . '/components/' . $com_name . '/' . $section . '/' . $section . '.php');
} else {
Router::set404();
}
}
return ob_get_clean();
}
示例6: _absent_
public function _absent_()
{
switch (Request::get('action')) {
case 'login':
$username = Request::post('username', true, Validator::STRICT_STRING);
$password = Request::post('password');
$user = (new Db())->getRow('SELECT * FROM ##users WHERE `username`=?s LIMIT 1', $username, MYSQLI_ASSOC);
if (!$user || crypt($password, $user['password']) !== $user['password'] || $user['username'] !== $username) {
throw new ValidatorException('Неверное имя пользователя или пароль');
}
session_regenerate_id(true);
$_SESSION['user'] = $user;
break;
case 'logout':
$_SESSION = [];
session_destroy();
setcookie('PHPSESSID', '', time() - 3600);
break;
default:
Router::set404();
}
}
示例7: _changeOrdering
protected function _changeOrdering($id, $new_order)
{
Router::set404();
}
示例8: toCamelCase
} else {
$com = Request::get('com');
if (!is_dir(ADMIN_ROOT . '/components/' . $com)) {
Router::set404();
}
if (is_file(ADMIN_ROOT . '/components/' . $com . '/config.php')) {
require_once ADMIN_ROOT . '/components/' . $com . '/config.php';
}
if (is_file(ADMIN_ROOT . '/components/' . $com . '/SectionController.php')) {
Load::controller(ADMIN_ROOT . '/components/' . $com . '/SectionController.php', Request::get('section', false));
} else {
$com_dirs = FileSys::getDirs(ADMIN_ROOT . '/components/' . $com);
$forbidden_dir = ['client'];
$section = Request::get('section');
if (in_array($section, $com_dirs) && !in_array($section, $forbidden_dir)) {
Load::manager(ADMIN_ROOT . '/components/' . $com . '/' . $section . '/' . toCamelCase($section) . 'Manager.php');
} else {
Router::set404();
}
}
}
} catch (SystemException $e) {
header('HTTP/1.0 500 Internal Server Error');
echo $e->getError();
} catch (ValidatorException $e) {
header('HTTP/1.0 400 Bad Request');
echo $e->getError();
} catch (AccessException $e) {
header('HTTP/1.0 403 Forbidden');
echo $e->getError();
}