html 助手在 CakePHP 上生成带有索引和分机的错误 URL


html helper generate bad url with index and ext on CakePHP

问题很简单,

我尝试使用以下代码生成与 Html 助手的链接:

echo $this->Html->link('<span>PDF</span>', array('action' => 'index', 'ext' => 'pdf'));
echo $this->Html->link('<span>PDF</span>', array('action' => 'index', 'ext' => 'pdf', 'full_base' => true));

它生成:

<a href="/users.pdf" class="action pdf-action"><span>PDF</span></a>

因此,Cake 自己决定,如果操作是索引,则不在 url 中生成/index,并且文档上没有选项可以避免这种情况。

有人知道我能做什么吗?

谢谢建议。

编辑:

我尝试使用路由器生成网址,结果相同:

echo $this->Html->link('<span>PDF</span>', Router::url(array('controller' => 'users', 'action' => 'index', 'ext' => 'pdf'), true), array('class' => 'action pdf-action', 'escape' => false));

在路由文件上使用此代码解决。

Router::connect('/:controller/index', array('action' => 'index'));

当操作是索引时,它基本上强制将索引放入所有控制器中。下一步找到如何仅在有扩展时强制它。