本文整理汇总了PHP中Zend_Controller_Router_Rewrite::addRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Router_Rewrite::addRoute方法的具体用法?PHP Zend_Controller_Router_Rewrite::addRoute怎么用?PHP Zend_Controller_Router_Rewrite::addRoute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Router_Rewrite
的用法示例。
在下文中一共展示了Zend_Controller_Router_Rewrite::addRoute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initRoutes
/**
* Routes initialization
*
* @return Zend_Controller_Router
*/
protected function _initRoutes()
{
$this->bootstrapOptions();
$router = new \Zend_Controller_Router_Rewrite();
foreach (\NS\Service\AbstractService::getConfig() as $module => $config) {
if ($config->routes) {
foreach ($config->routes as $r => $routeConfig) {
$router->addRoute($module . '_' . $r, \Zend_Controller_Router_Route::getInstance($routeConfig));
}
}
}
\Zend_Controller_Front::getInstance()->setRouter($router);
return $router;
}
示例2: getRouter
public function getRouter()
{
$router = new Zend_Controller_Router_Rewrite();
$router->addRoute('foo', new Zend_Controller_Router_Route_Static('/foo/bar', array()));
return $router;
}
示例3: array
// http://example.com/
// -> controller => index
// action => index
// params => array()
// http://example.com/user
// -> controller => user
// action => index
// params => array()
// http://example.com/user/new
// -> controller => user
// action => new
// params => array()
// http://example.com/user/show/id/1/name/adam
// -> controller => user
// action => show
// params => array('id'=>1, 'name'=>'adam)
// More complicated routing is available through the RewriteRouter
$router = new Zend_Controller_Router_Rewrite();
// RewriteRouter automatically provides the following route:
// $this->addRoute('default',
// new Zend_Controller_Router_Route(':controller/:action/*',
// array('controller' => 'index', 'action' => 'index')));
// If want this, comment the following line
// $router->removeDefaultRoutes();
$router->addRoute('build', new Zend_Controller_Router_Route('build', array('controller' => 'search', 'action' => 'build')));
$router->addRoute('newSearch', new Zend_Controller_Router_Route('search', array('controller' => 'search', 'action' => 'new')));
$router->addRoute('showSearch', new Zend_Controller_Router_Route('search/:q', array('controller' => 'search', 'action' => 'show')));
$router->addRoute('tagIndex', new Zend_Controller_Router_Route('tag', array('controller' => 'tag', 'action' => 'index')));
$router->addRoute('tagShow', new Zend_Controller_Router_Route('tag/:tag', array('controller' => 'tag', 'action' => 'show')));
$router->addRoute('standard', new Zend_Controller_Router_Route(':controller/:action/:id'));
Zend_Registry::set('router', $router);
示例4: testMultipleChainsResettingPathInfoInSegmentBlock
/**
* @throws Zend_Controller_Router_Exception
*/
public function testMultipleChainsResettingPathInfoInSegmentBlock()
{
$foo = new Zend_Controller_Router_Route_SubclassTest('notfoo');
$bar = new Zend_Controller_Router_Route_SubclassTest('bar', array('baz' => 'no'));
$chain = $foo->chain($bar);
$static = new Zend_Controller_Router_Route_SimpleSubclassTest('/foo', array('foo' => 'foo'));
$rewrite = new Zend_Controller_Router_Rewrite();
$rewrite->addRoute('static', $static);
// First In Last Out, we want this to be matched against second
$rewrite->addRoute('chain', $chain);
$request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo');
$res = $rewrite->route($request);
$this->assertEquals('foo', $res->getParam('foo'), 'Route did not match');
$this->assertEquals('static', $rewrite->getCurrentRouteName(), 'Routing did not match expected route');
}
示例5: array
require_once 'Zend/Controller/Router/Route.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Config.php';
require_once 'Zend/Db.php';
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
// load configuration
$config = new Zend_Config_Ini('../application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// setup database
$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
$router = new Zend_Controller_Router_Rewrite();
$route1 = new Zend_Controller_Router_Route('workout/:id', array('controller' => 'workout', 'action' => 'index'));
$route2 = new Zend_Controller_Router_Route('workout/:id/:date', array('controller' => 'workout', 'action' => 'index'));
$user = new Zend_Controller_Router_Route('users/:id', array('controller' => 'Users', 'action' => 'index'));
$router->addRoute('workout', $route1);
$router->addRoute('workout2', $route2);
$router->addRoute('users', $user);
/**
* Setup controller
*/
$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../application/default/controllers')->setRouter($router);
/*->setBaseUrl('api/');*/
$controller->throwExceptions(false);
// should be turned on in development time
$controller->dispatch();
示例6: define
<?php
$environment = 'development';
// application/bootstrap.php
//
// Step 1: APPLICATION CONSTANTS - Set the constants to use in this application.
// These constants are accessible throughout the application, even in ini
// files. We optionally set APPLICATION_PATH here in case our entry point
// isn't index.php (e.g., if required from our test suite or a script).
defined('APPLICATION_PATH') or define('APPLICATION_PATH', dirname(__FILE__));
defined('APPLICATION_ENVIRONMENT') or define('APPLICATION_ENVIRONMENT', 'development');
$router = new Zend_Controller_Router_Rewrite();
//$route = new Zend_Controller_Router_Route(
$route = new Zend_Controller_Router_Route_Regex('([A-Fa-f0-9]+)', array('controller' => 'url', 'action' => 'redirect'), array('urlid' => 1));
$router->addRoute('index', $route);
// Step 2: FRONT CONTROLLER - Get the front controller.
// The Zend_Front_Controller class implements the Singleton pattern, which is a
// design pattern used to ensure there is only one instance of
// Zend_Front_Controller created on each request.
$frontController = Zend_Controller_Front::getInstance();
// Step 3: CONTROLLER DIRECTORY SETUP - Point the front controller to your action
// controller directory.
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
// Step 4: APPLICATION ENVIRONMENT - Set the current environment.
// Set a variable in the front controller indicating the current environment --
// commonly one of development, staging, testing, production, but wholly
// dependent on your organization's and/or site's needs.
$frontController->setParam('env', APPLICATION_ENVIRONMENT);
$frontController->setRouter($router);
// LAYOUT SETUP - Setup the layout component
// The Zend_Layout component implements a composite (or two-step-view) pattern
示例7: array
<?php
$router = new Zend_Controller_Router_Rewrite();
//$router->removeDefaultRoutes();
$cnf = Zend_Registry::get('cnf');
$db = Zend_Db::factory($cnf->db);
$select = $db->query("\r\n\tselect\r\n\t\tsu.Name AS Name,\r\n\t\tsm.Controller AS Controller,\r\n\t\tCONCAT(sm.Module,'\\/',sm.Controller,'\\/?',su.URL_regexp) AS URL_regexp,\r\n\t\tsu.URL_vars AS URL_vars,\r\n\t\tsu.Action AS Action,\r\n\t\tsm.Module AS Module\r\n\tfrom\r\n\t\tadmin_menu sm,\r\n\t\tadmin_urls su\r\n\twhere\r\n\t\tsm.ID=su.Menu_id\r\n\t\tand sm.Hidden=0\r\n");
$menu = $select->fetchAll();
for ($i = 0; $i < count($menu); $i++) {
$vars = array();
$d = explode(",", $menu[$i]['URL_vars']);
for ($j = 0; $j < count($d); $j += 2) {
$vars[$d[$j]] = (int) $d[$j + 1];
}
$router->addRoute($menu[$i]['Name'], new Zend_Controller_Router_Route_Regex("^" . $menu[$i]['URL_regexp'] . "\$", array('module' => $menu[$i]['Module'], 'controller' => $menu[$i]['Controller'], 'action' => $menu[$i]['Action']), $vars));
}
示例8: _addHomepageRedirect
/**
* Adds a redirect route for the homepage.
*
* A redirect is required to make a "homepage" that is an external URL, an
* admin URL, or a URL with a query string.
*
* @param string $uri The absolute uri to redirect to the default route to
* @param Zend_Controller_Router_Rewrite $router The router
* @return boolean True if the route was successfully added, else false.
*/
protected function _addHomepageRedirect($uri, $router)
{
// Handle possible internal links by stripping the base URL
$uri = $this->_leftTrim($uri, PUBLIC_BASE_URL);
if ($uri == '' || $uri == '/' || strpos($uri, '?') === 0 || strpos($uri, '/?') === 0) {
return false;
}
$router->addRoute(self::HOMEPAGE_ROUTE_NAME, new Zend_Controller_Router_Route('/', array('controller' => 'redirector', 'action' => 'index', 'redirect_uri' => $uri)));
return true;
}
示例9: addAdminRoutes
public static function addAdminRoutes(Zend_Controller_Router_Rewrite $router)
{
//Dashboard
$route = new Zend_Controller_Router_Route('/admin', array('module' => 'admin', 'controller' => 'index', 'action' => 'index'));
$router->addRoute('admin_index', $route);
//Folder
$route = new Zend_Controller_Router_Route('/admin/folder/:folder_id', array('module' => 'admin', 'controller' => 'folder', 'action' => 'view'));
$router->addRoute('admin_view_folder', $route);
$route = new Zend_Controller_Router_Route('/admin/folder/', array('module' => 'admin', 'controller' => 'folder', 'action' => 'view'));
$router->addRoute('admin_view_root_folder', $route);
$route = new Zend_Controller_Router_Route('/admin/folder/:folder_id/create', array('module' => 'admin', 'controller' => 'folder', 'action' => 'create'));
$router->addRoute('admin_create_folder', $route);
$route = new Zend_Controller_Router_Route('/admin/folder/:folder_id/delete', array('module' => 'admin', 'controller' => 'folder', 'action' => 'delete'));
$router->addRoute('admin_delete_folder', $route);
//Template
$route = new Zend_Controller_Router_Route('/admin/template', array('module' => 'admin', 'controller' => 'template', 'action' => 'viewAll'));
$router->addRoute('admin_view_templates', $route);
$route = new Zend_Controller_Router_Route('/admin/template/create', array('module' => 'admin', 'controller' => 'template', 'action' => 'create'));
$router->addRoute('admin_create_template', $route);
$route = new Zend_Controller_Router_Route('/admin/template/:template_id/delete', array('module' => 'admin', 'controller' => 'template', 'action' => 'delete'));
$router->addRoute('admin_delete_template', $route);
//File
$route = new Zend_Controller_Router_Route('/admin/foler/:folder_id/file/create', array('module' => 'admin', 'controller' => 'file', 'action' => 'create'));
$router->addRoute('admin_create_file', $route);
$route = new Zend_Controller_Router_Route('/admin/file/:file_id/delete', array('module' => 'admin', 'controller' => 'file', 'action' => 'delete'));
$router->addRoute('admin_delete_file', $route);
//Page
$route = new Zend_Controller_Router_Route('/admin/folder/:folder_id/page/create', array('module' => 'admin', 'controller' => 'page', 'action' => 'create'));
$router->addRoute('admin_create_page', $route);
$route = new Zend_Controller_Router_Route('/admin/page/:page_id/delete', array('module' => 'admin', 'controller' => 'page', 'action' => 'delete'));
$router->addRoute('admin_delete_page', $route);
$route = new Zend_Controller_Router_Route('/admin/page/:page_id/edit', array('module' => 'admin', 'controller' => 'page', 'action' => 'edit'));
$router->addRoute('admin_edit_page', $route);
$route = new Zend_Controller_Router_Route('/admin/page/:page_id/render-for-edit', array('module' => 'admin', 'controller' => 'page', 'action' => 'renderForEdit'));
$router->addRoute('admin_render_for_edit_page', $route);
$route = new Zend_Controller_Router_Route('/admin/page/:page_id/save-sections', array('module' => 'admin', 'controller' => 'page', 'action' => 'saveSections'));
$router->addRoute('admin_save_page_sections', $route);
//Setup
$route = new Zend_Controller_Router_Route('/setup/site-config', array('module' => 'admin', 'controller' => 'setup', 'action' => 'siteConfig'));
$router->addRoute('admin_setup_site_config', $route);
//User
$route = new Zend_Controller_Router_Route('/admin/user', array('module' => 'admin', 'controller' => 'user', 'action' => 'viewAll'));
$router->addRoute('admin_view_users', $route);
$route = new Zend_Controller_Router_Route('/admin/user/create', array('module' => 'admin', 'controller' => 'user', 'action' => 'create'));
$router->addRoute('admin_create_user', $route);
$route = new Zend_Controller_Router_Route('/admin/user/edit/:user_id', array('module' => 'admin', 'controller' => 'user', 'action' => 'edit'));
$router->addRoute('admin_edit_user', $route);
$route = new Zend_Controller_Router_Route('/admin/user/:user_id/delete', array('module' => 'admin', 'controller' => 'user', 'action' => 'delete'));
$router->addRoute('admin_delete_user', $route);
$route = new Zend_Controller_Router_Route('/admin/user/login', array('module' => 'admin', 'controller' => 'user', 'action' => 'login'));
$router->addRoute('admin_login_user', $route);
$route = new Zend_Controller_Router_Route('/admin/user/logout', array('module' => 'admin', 'controller' => 'user', 'action' => 'logout'));
$router->addRoute('admin_logout_user', $route);
}
示例10: array
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), get_include_path())));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
//**************** 自定义部分 Start *********************//
require_once APPLICATION_PATH . '/modules/admin/controllers/BaseController.php';
require_once APPLICATION_PATH . '/modules/home/controllers/BaseController.php';
//定义当前 public 所在的路径
defined("PUBLIC_PATH") || define("PUBLIC_PATH", realpath(dirname(__FILE__)));
$front = Zend_Controller_Front::getInstance();
//设定后台模块
$front->addModuleDirectory(APPLICATION_PATH . '/modules');
$front->setDefaultModule("home");
$router = new Zend_Controller_Router_Rewrite();
$route = new Zend_Controller_Router_Route('home/:id', array('controller' => 'Index', 'action' => 'index'));
// 使用路由器装载路由协议
$router->addRoute('home', $route);
$front->setRouter($router);
defined("BASE_URL") or define("BASE_URL", $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME']);
$front->throwExceptions(true);
//引入测试所需文件
require_once PUBLIC_PATH . '/FirePHPCore/fb.php';
FB::info(get_include_path());
//**************** 自定义部分 End *********************//
try {
$application->bootstrap()->run();
} catch (Zend_Exception $se) {
echo $se->getTrace();
}