Take for CakePHP [英] Twig for CakePHP

查看:48
本文介绍了Take for CakePHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Twig与CakePHP一起使用,所以我安装了此插件:

https: //github.com/predominant/TwigView

I am trying to use Twig with CakePHP, so I installed this plugin:
https://github.com/predominant/TwigView

在CakePHP的演示中,我们建立了一个博客,我可以在tpl文件中使用它:

And in CakePHP's demo, we build a blog, and I can use this in a tpl file:

{% for post in posts %}
<tr>
    <td>{{post.Post.id}}</td>
    <td>{{post.Post.title}}</td>
    <td>Edit | Delete</td>
    <td>{{post.Post.created|date("F j, Y")}}</td>
</tr>
{% endfor %}

我无法工作,正在转换:

What I can't get to work, is converting this:

<?php
echo $this->Html->link(
    'Add Post', array('controller' => 'posts', 'action'     => 'add')
);
?>

我已经尝试了所有这些方法,但都不起作用:

I have tried all of these, and none of them work:

{{ html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}
{{ _view.html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}
{{ this.html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}

我没有任何错误,只是被替换为空。有人知道我该如何解决这个问题?

I don't get any errors, it just gets replaced with nothing. Anyone know how I can fix this issue?

推荐答案

您必须在控制器中显式声明助手以使其起作用:

You have to explicitly declare the helpers in the controller to make it work:

public $helpers = array('Html', 'Form');

请参见GitHub问题#14 #13 其中我从这里得到的。

See GitHub issue #14 and #13 where I got this from.

这篇关于Take for CakePHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆