本文整理汇总了PHP中router类的典型用法代码示例。如果您正苦于以下问题:PHP router类的具体用法?PHP router怎么用?PHP router使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolve_controller_callback
/**
* Given an action, find the controller and method responsible for
* handling the action.
*
* In addition, send some extra variables to the controller
* and initialize it.
*
* @param string $action
* @return array
*/
public function resolve_controller_callback($action)
{
/** @var $controller controller_abstract */
list($controller, $method) = $this->router->route_action($action);
$controller->init($action);
return array($controller, $method);
}
示例2: init
public function init()
{
$this->setRequestParams();
$rout = new router($this->contData);
$contName = $rout->getController();
$this->cont = new $contName();
$this->cont->init($this->contData);
}
示例3: __construct
public function __construct(router $router, user $user, array $data)
{
$this->router = $router;
$this->route = $router->getRoute();
$this->user = $user;
$this->parameters = $router->getParameters();
$this->data = $data;
$this->db = new db(HOST, USER, PASSWORD, DATABASE, ENCODING);
}
示例4: __construct
public function __construct()
{
parent::__construct();
if (!users_helper::isLoggedin() || !session::permission('site_access_cp', 'system')) {
router::redirect('cp/users/login');
}
}
示例5: getJson
public function getJson($addWhere = '', $addSql = '', $showMax = 12)
{
$sort = input::getInput("mix.sort") ? input::getInput("mix.sort") : 'id';
$order = input::getInput("mix.order") ? input::getInput("mix.order") : "asc";
$page = input::getInput("mix.page") ? input::getInput("mix.page") : 1;
$rows = input::getInput("mix.rows") ? input::getInput("mix.rows") : 10;
$db = sf::getLib("db");
if ($select) {
$sql = $select . " ";
} else {
$sql = "SELECT * FROM `" . $this->table . "` ";
}
$addWhere && ($sql .= "WHERE " . $addWhere . " ");
if ($addSql) {
$sql .= $addSql . " ";
} else {
$sql .= " ORDER BY {$sort} {$order} ";
}
if (!router::get("totalnum" . $key)) {
$query = $db->query($sql);
$total = $db->num_rows($query);
} else {
$total = router::get("totalnum" . $key);
}
$sql .= "LIMIT " . $rows * ($page - 1) . "," . $rows;
$query = $db->query($sql);
while ($row = $db->fetch_array($query)) {
$result[] = $this->fillObject($row)->toArray();
}
return '{"total":' . $total . ',"rows":' . json_encode($result) . '}';
}
示例6: __construct
public function __construct()
{
parent::__construct();
if (!config::item('news_blog', 'news') && uri::segment(1) != 'news') {
router::redirect('news/' . utf8::substr(uri::getURI(), 5));
}
}
示例7: dispatch
public static function dispatch()
{
$uri = visitor::uri();
$target = router::parse_pps_uri($uri);
if (config::get_module('view.default_skeleton', false) !== false) {
if (config::get_module('view.cache_pps_in_server', false)) {
$use_cache = false;
if (defined('kern\\data_dir')) {
$version_key = config::get_kern('version_key', router::default_version_key);
$cache_dir = data_dir . '/cache/' . $serve_mode . '/' . $target->get_param($version_key, '0');
$cache_file = $cache_dir . '/' . sha1($uri) . '.cache';
if (is_readable($cache_file)) {
$use_cache = true;
}
}
if ($use_cache) {
$content = file_get_contents($cache_file);
} else {
$content = pps_rendor::render_for($target);
if (!is_dir($cache_dir)) {
@mkdir($cache_dir, 0777, true);
}
@file_put_contents($cache_file, $content);
}
} else {
$content = pps_rendor::render_for($target);
}
} else {
$content = '';
}
visitor::set_content($content);
}
示例8: signUP
public function signUP($username, $pass, $passControl)
{
if ($pass !== $passControl) {
return 'The passwords do not match.';
}
if (!ctype_alnum(str_replace(array('-', '_'), '', $username))) {
return 'This username contains forbidden characters. Please stick to alphanumerics, hyphens, and underscores.';
}
if (strlen(trim($username)) < 4 || strlen(trim($username)) > 32) {
return 'Your username is either too short or too long. It has to consist of 4-32 characters.';
}
if (strlen(trim($pass)) < 4 || strlen(trim($pass)) > 32) {
return 'This is not a valid password (too short or too long).';
}
$userRows = database::fetchRows('users', 'id', 'name', $username);
if ($userRows->num_rows != 1) {
$user['name'] = trim($username);
$user['password'] = trim($pass);
database::addRow('users', $user);
$_SESSION['user'] = $username;
$_SESSION['loggedIn'] = true;
router::redirect('u/' . $username);
} else {
return 'This username has already been taken.';
}
}
示例9: confirm
public function confirm($action = '')
{
// Do we have necessary data?
if (input::get('oauth_token') && input::get('oauth_verifier')) {
// Get temporary access token
$this->initialize(session::item('twitter', 'remote_connect', 'token'), session::item('twitter', 'remote_connect', 'secret'));
$access = $this->twitter->getAccessToken(input::get('oauth_verifier'));
// Do we have temporary token?
if ($access) {
// Get saved token
$token = $this->getToken(0, $access['user_id']);
// Do we have saved token or are we logging in?
if ($token || $action == 'login' && $token) {
$this->users_model->login($token['user_id']);
router::redirect(session::item('slug') . '#home');
} elseif (!$token || $action == 'signup') {
// Get user data
$this->initialize($access['oauth_token'], $access['oauth_token_secret']);
$user = $this->getUser($access['user_id']);
// Do we have user data?
if ($user && isset($user->id)) {
$connection = array('name' => 'twitter', 'twitter_id' => $user->id, 'token' => $access['oauth_token'], 'secret' => $access['oauth_token_secret']);
session::set(array('connection' => $connection), '', 'remote_connect');
$account = array('username' => isset($user->name) ? $user->name : '');
session::set(array('account' => $account), '', 'signup');
router::redirect('users/signup#account');
}
}
}
}
router::redirect('users/login');
}
示例10: _sendFeedback
protected function _sendFeedback()
{
// Check if demo mode is enabled
if (input::demo()) {
return false;
}
// Extra rules
$rules = array('name' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 2, 'max_length' => 255)), 'email' => array('rules' => array('required', 'is_string', 'trim', 'valid_email', 'min_length' => 4, 'max_length' => 255)), 'subject' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 5, 'max_length' => 255)), 'message' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 10, 'max_length' => 10000)));
if (config::item('feedback_captcha', 'feedback') == 1 || config::item('feedback_captcha', 'feedback') == 2 && !users_helper::isLoggedin()) {
$rules['captcha'] = array('rules' => array('is_captcha'));
}
validate::setRules($rules);
// Validate form values
if (!validate::run($rules)) {
return false;
}
// Get values
$email = input::post('email');
$subject = input::post('subject');
$message = input::post('message') . "\n\n--\n" . input::post('name') . ' <' . input::post('email') . '>' . "\n" . input::ipaddress();
// Send feedback
if (!$this->feedback_model->sendFeedback($email, $subject, $message)) {
if (!validate::getTotalErrors()) {
view::setError(__('send_error', 'system'));
}
return false;
}
// Success
view::setInfo(__('message_sent', 'feedback'));
router::redirect('feedback');
}
示例11: processInput
public function processInput()
{
if (isset($_GET['push'])) {
$this->model->pushSettings();
router::redirectMessage('index.php?view=device', 'Push Successful');
}
}
示例12: __construct
public function __construct()
{
parent::__construct();
// Is this control panel?
if (strtolower(uri::segment(1)) == 'cp' && !$this->isLoggedin() && (uri::segment(2) != 'users' || uri::segment(3) != 'login')) {
router::redirect('cp/users/login');
}
}
示例13: getInstance
/**
* 创建唯一router实例
* @access public
* @static
* @return Object routerObject
* @example $router = router::getInstance()
*/
public static function getInstance()
{
if (!self::$_instance instanceof router) {
self::$_instance = new self();
log::accessLog("Create router instance success");
}
log::returnLog(self::$_instance);
return self::$_instance;
}
示例14: run
public static function run()
{
spl_autoload_register(__CLASS__ . "::" . 'autoload');
if (app_config::$use_db == true) {
db::set_db_config(app_config::$db);
}
url::init(app_config::$url);
router::route(app_config::$router, app_config::$re_route);
}
示例15: __construct
public function __construct()
{
/**
* Get the database and set the config
*/
$db = new database();
$db->setup($a = array('hostname' => 'localhost', 'username' => 'govhack', 'password' => 'govhack', 'database' => 'govhack_ip'))->connect();
/**
* Load the page controllers
*/
$search = new search($db);
$index = new index();
$about = new about();
/**
* Get the application router
*/
$router = new router();
$router->add('/', $index)->add('/index', $index)->add('/about', $about)->add('/search', $search)->add('/*', $search);
$router->route();
}