0
我怎么能够从数据库创建动态路由。 我使用自定义路由器,但是,我无法将教条链接与我的自定义路由器进行集成。 主要难点在于,Factory无法与自定义路由类连接。 有谁知道如何在ZF3中连接路由与数据库?来自数据库的ZF3动态路由
我怎么能够从数据库创建动态路由。 我使用自定义路由器,但是,我无法将教条链接与我的自定义路由器进行集成。 主要难点在于,Factory无法与自定义路由类连接。 有谁知道如何在ZF3中连接路由与数据库?来自数据库的ZF3动态路由
你需要细分路线,例如。
'blogpost' => [
'type' => Segment::class,
'options' => [
'route' => '/novost/:id',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'blogPost',
],
],
],
通知
:ID
ID在路线
动态的变量,你retrive它里面的行动,比如
$id = $this->params()->fromRoute('id');
所以你可以从数据库获取此路由的数据并将其提供给ViewModel。例如:
$post = $this->model->getBlogPost($id);
$vm = new ViewModel(['post' => $post]);
return $vm;
通知,你也可以有可选的变量与途径括号 - > [/:变量]
当建立与URL链接帮手不要忘了变数。
$this->url('blogpost',['id'=>$someid]);
更多信息:https://docs.zendframework.com/tutorials/in-depth-guide/understanding-routing/#segment-routes