【发布时间】:2020-04-26 01:37:48
【问题描述】:
我有一个应该为锚标记生成 href 的路由,但我没有得到 href:
<a href="" style="color:white !important" class="btn btn-info postlist">Update</a>
我上面的代码是:
data[i]["confirm"] = '<a href="<?=route_to('updatePost', 1) ?>" style="color:white !important" class="btn btn-info postlist">Update</a>';
我的路线是:
//$routes->add('post/(:id)', 'App/Controllers/Post::updatepost/$1');
$routes->add('post/(:id)', 'Post::updatepost/$1', ['as' => 'updatePost']);
我期待类似this
注意:尝试了未命名和命名的方式都没有生成任何href
【问题讨论】:
-
即使他们的例子(有错字)也不起作用。似乎在您添加 (:id) 和朋友的那一刻,它会引发错误。我必须深入研究代码,但我现在有点忙。如果你让它像 /post 一样简单,那就行了
-
(:any) 有效。你试过了吗,是的,我还没有完全放弃:)
-
请注意您对 data[i]["confirm"] = "link code" 的使用非常确定。那是 $data[$i]['confirm'] 吗?
-
@TimBrownlaw 我在这里学习特别是路由,我需要在这方面进行改进。至于索引它的
i不是$i.. 我没有尝试过这个但会尝试这个我需要专注于另一个答案:)
标签: routes href codeigniter-4 named-routing