0

问题很简单,

我尝试使用以下代码生成与 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 自己决定不在 u​​rl 中生成 /index,并且文档中没有选项可以避免这种情况。

有人知道我能做什么吗?

谢谢指教。

编辑:

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

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

1 回答 1

0

在路线文件中使用此代码解决。

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

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

于 2013-09-13T08:43:25.313 回答