Gna*_*agy 0 php zend-framework2
我的任务是探索创建动态网址的可能性.我们试图实现的是为客户提供域名服务.
例如.www.example.com/clients/john/
例如.www.example.com/clients/bill/
这些网址不是固定的,但必须在客户每次在我们的网站注册时动态制作.我们的URL是控制器和动作的构建.像www.example.com/controller/action一样.
如何在PHP Zend Framework 2中实现这一目标?
非常感谢提前!
您只需要ZF2手册:
我建议使用段路由 你可以定义它们:
'client' => array(
'route' => '/clients/:username',
'constraints' => array(
'username' => '[a-zA-Z][a-zA-Z0-9-]+', //accepted value pattern
),
'defaults' => array( //which action to invoke
'controller' => 'Application\Controller\ClientController',
'action' => 'showclient',
),
));
Run Code Online (Sandbox Code Playgroud)
然后你可以用url helper创建一个url,如:
$this->url('client', array('username' => 'John'));
Run Code Online (Sandbox Code Playgroud)
在您的控制器中,您将能够获得以下username参数:
$this->params()->fromRoute('username');
Run Code Online (Sandbox Code Playgroud)