Rei*_*.85 9 php url action zend-framework2
在zend 2中,我无法想出从我想要的任何地方生成Url
我得到动作和控制器所以我试试这个:
$this->url('myControllerName', array('action' => 'myActionName'));
Run Code Online (Sandbox Code Playgroud)
但是这会返回一个对象,我只想要这个路由的完整URL字符串
有人可以帮我找到合适的方法吗?
编辑:根据斯托扬的说法,也许我在我的路线上犯了一个错误.这是我的module.config的一部分
'router' => array (
'routes' => array (
'indexqvm' => array (
'type' => 'segment',
'options' => array (
'route' => '/Indexqvm[/:action][/:id_event]',
'constraints' => array (
'action' => '[a-zA-Z][a-zA-Z0-9_-]+',
'id_event' => '[0-9]+'
),
'defaults' => array (
'controller' => 'Qvm\Controller\Indexqvm',
'action' => 'index'
)
)
),
Run Code Online (Sandbox Code Playgroud)
我的电话:
echo $this->url('indexqvm', array('action' => 'list-index'));
Run Code Online (Sandbox Code Playgroud)
错误:可捕获的致命错误:类Zend\Mvc\Controller\Plugin\Url的对象无法转换为字符串
Sto*_*mov 25
在调用之前使用echo $this->url(...)(参见下文),这将显示整个URL.
<?php echo $this->url('route-name', $urlParams, $urlOptions); ?>
Run Code Online (Sandbox Code Playgroud)
请注意,第一个参数url()是[module]/config/module.config.php文件中指定的路径名称.
请参阅此有关ZF2的URL视图助手的更多信息.
编辑以回答问题编辑:
以上部分与使用URL视图助手有关.
如果您想在控制器中使用URL,则需要URL控制器插件.
<?php $url = $this->url()->fromRoute('route-name', $params, $options); ?>
Run Code Online (Sandbox Code Playgroud)
这是对该控制器插件的ZF2手册的引用.
希望这可以帮助 :)
斯托扬
| 归档时间: |
|
| 查看次数: |
27015 次 |
| 最近记录: |