2011-01-08 53 views
6

如何更改扩展名从.ctp CakePHP的视图来.PHPCakePHP的查看更改扩展

我已经看到有这条线在/cake/libs/view.php var $ext = '.ctp';那台分机却怎么也我从我的/ app /文件夹中执行,因此它不会影响Cake核心文件。

感谢

回答

10

您可以在您的AppController扩展与

public $ext = '.yourext'; 
+0

多个扩展如接受.php和.ctp怎么可能? – Cameron 2011-01-08 21:38:22

1

这是回复到卡梅隆的关于使用多个扩展的事实CakePHP的光不允许的问题评论你可以指定多个扩展。

我对单个站点使用Mustache,该站点对站点的不同部分使用merb,rails2,rails3和cakephp。蛋糕网站“接收”常见布局元素的胡须文件,但这些模板有一个'.mustache'文件扩展名,我的蛋糕网站不会识别。我的解决方法基本上是dhofstet建议在您的特定用例的背景下构建的。总之,创建一个包装,可能是这个样子:

<? 
    $tmp = $this->ext; 
    $this->ext = '.mustache'; 
?> 
<?= $m->render($this->renderElement('moznav/advanced_header'), array('foo' => $bar)) ?><br /> 

<? $this->ext = $tmp; ?> 

当流返回给调用者,你继续使用原生文件扩展名。

0

How can I change the extension for CakePHP Views from .ctp to .php

I have seen there is this line in /cake/libs/view.php var $ext = '.ctp'; that sets the extension but how can I do it from my /app/ folder so it doesn't effect Cake core files.

例如:

  • 你有看法posts/add.ctp
  • 现在重新命名add.ctpadd.php
  • 然后运行.../posts/add消息错误显示:

    Error: The view for PostsController::add() was not found.

    到您的应用程序可以了解延伸.php,您添加线公众$ext = '.php'PostsController.php

  • 现在,您再次运行。 .posts/add => okie,CakePHP的理解extention .php

注意:如果你使用一个名为.ctp atrribute $ext = '.php'但文件视图,CakePHP的extention .ctp将默认使用

0

我发现这个职位,因为我有同样的问题。这在Github的主要TwigView插件文档中没有提及。我厌倦了那些只解释了一半事情的文件,我们不得不猜测下半场。这是浪费大量时间,毫无意义地减慢项目速度。