'router' => array(
'routes' => array(
'user' => array(
'type' => 'Segment',
'options' => array(
'route' => '/user[/]',
'defaults' => array(
'controller' => 'UserController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'profile' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:id][/]',
'constraints' => array(
'id' => '[a-zA-Z0-9_-]+'
),
'defaults' => array(
'action' => 'get'
),
),
'may_terminate' => true,
'child_routes' => array(
'blog' => array(
'type' => 'Segment',
'options' => array(
'route' => 'blog[/]',
'constraints' => array(
),
'defaults' => array(
'action' => 'blog'
)
),
'may_terminate' => true,
'child_routes' => array(
'post' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:post_id][/]',
'constraints' => array(
'post_id' => '[a-zA-Z0-9_-]+'
),
'defaults' => array(
'action' => 'post'
)
),
'may_terminate' => true,
),
),
),
), //profile child_routes end
), //profile end
), //user child_routes end
), //user end
),
),
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/url',
'defaults' => array(
'controller' => 'Application\Controller\User',
'action' => 'url',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
'user_list' => array(
'type' => 'Segment',
'options' => array(
'route' => '/user[/]',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'User',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'user' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:name][/]',
'constraints' => array(
'name' => '[a-zA-Z0-9_-]+',
),
'defaults' => array(
'action' => 'show',
),
),
'may_terminate' => true,
'child_routes' => array(
'blog_list' => array(
'type' => 'Segment',
'options' => array(
'route' => 'blog[/]',
'constraints' => array(
),
'defaults' => array(
'controller' => 'Blog',
'action' => 'index',
)
),
'may_terminate' => true,
'child_routes' => array(
'blog' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:blog_id]',
'constraints' => array(
'blog_id' => '[0-9]+',
),
'defaults' => array(
'action' => 'show',
)
),
'may_terminate' => true,
),
),
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Application\Controller\User' => 'Application\Controller\UserController',
'Application\Controller\Blog' => 'Application\Controller\BlogController',
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
?>
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class UserController extends AbstractActionController {
public function urlAction() {
$name = 'jing';
$blogId = 1;
$urls = array(
$this->url()->fromRoute('user_list'),
$this->url()->fromRoute('user_list/user', array('name' => $name)),
$this->url()->fromRoute('user_list/user/blog_list', array('name' => $name)),
$this->url()->fromRoute('user_list/user/blog_list/blog', array('name' => $name, 'blog_id' => $blogId)),
);
$view = new ViewModel(compact('urls'));
$view->setTerminal(true);
return $view;
}
public function indexAction() {
$view = new ViewModel();
// 禁用布局模板
$view->setTerminal(true);
return $view;
}
public function showAction() {
$username = $this->params()->fromRoute('name');
$view = new ViewModel(compact('username'));
$view->setTerminal(true);
return $view;
}
}
?>
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class BlogController extends AbstractActionController {
public function indexAction() {
$username = $this->params()->fromRoute('name');
$view = new ViewModel(compact('username'));
$view->setTerminal(true);
return $view;
}
public function showAction() {
$username = $this->params()->fromRoute('name');
$blogId = $this->params()->fromRoute('blog_id');
$view = new ViewModel(compact('username', 'blogId'));
$view->setTerminal(true);
return $view;
}
}
?>
<?php foreach ($urls as $url): ?> <a href="<?php echo $url;?>"><?php echo $url;?><a/><br /> <?php endforeach; ?>
$router = Yaf_Dispatcher::getInstance()->getRouter();
$route0 = new Yaf_Route_Rewrite('url', array(
'controller' => 'User',
'action' => 'url',
), array()
);
$route1 = new Yaf_Route_Rewrite('user', array(
'controller' => 'User',
'action' => 'index',
), array()
);
$route2 = new Yaf_Route_Regex('#user/([a-zA-Z0-9_-]+)#', array(
'controller' => 'User',
'action' => 'show',
), array(1 => 'name',)
);
$route3 = new Yaf_Route_Regex('#user/([a-zA-Z0-9_-]+)/blog#', array(
'controller' => 'Blog',
'action' => 'index',
), array(1 => 'name',)
);
$route4 = new Yaf_Route_Regex('#user/([a-zA-Z0-9_-]+)/blog/([0-9]+)#', array(
'controller' => 'Blog',
'action' => 'show',
), array(1 => 'name', 2 => 'blogId',)
);
$router->addRoute('url', $route0);
$router->addRoute('user_list', $route1);
$router->addRoute('user', $route2);
$router->addRoute("blog_list", $route3);
$router->addRoute("blog", $route4);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有