Dwoo / codeigniter:有没有办法将 php 中的数据分配给 INSIDE 模板中的 dwoo 变量?
纯 dwoo 等效项是:(
$dwoo->output('DwooTest/index', array('assignedVar' => 'Hello'));
我实际上将它与 codeigniter 一起使用 - 与 Phil Sturgeon 的库一起使用):
$this->dwooParser->parse('DwooTest/index', array('assignedVar' => 'Hello'));
然后在 index.php 内部
{$assignedVar} //outputs 'Hello'
<?php
$localVar = 'LocalVar';
?>
{$localVar} //output: error
有没有办法将数据从模板内的 php 传递到 dwoo var ?
为什么我使用它是因为我有一个需要一些预处理的视图(它是一种高级视图,所以我不想每次都将处理放在控制器内),在index.php内我有一个
require 'index.h.php' //(notation inspired from c++ header files)
与上面的例子中,index.h.php会处理$signedVar,并将数据放入$localVar中,然后数据的显示将在模板index.php中进行。
(顺便说一句,这个 Dwoo 东西的文档在哪里......我的意思是 wiki......就是它?)
Pure dwoo equivalent would be:
$dwoo->output('DwooTest/index', array('assignedVar' => 'Hello'));
(I am actually using it with codeigniter - with Phil Sturgeon's library):
$this->dwooParser->parse('DwooTest/index', array('assignedVar' => 'Hello'));
then inside index.php
{$assignedVar} //outputs 'Hello'
<?php
$localVar = 'LocalVar';
?>
{$localVar} //output: error
Is there a way to pass data from php inside the template to a dwoo var ?
Why I use this is because I have a view that needs some preprocessing of sorts (it sort of an advanced view, so I dont want to put the processing every time inside the controller ), inside the index.php I have a
require 'index.h.php' //(notation inspired from c++ header files)
In keeping with the above example, index.h.php would process $assignedVar, and put the data into $localVar, then the display of the data would take place inside the template index.php.
(Also on a side note, where is the documentation for this Dwoo thing... I mean that wiki... that is it ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在执行模板时,局部变量将保存到 Dwoo 对象的内部变量中。实际的模板代码在 Dwoo 对象的上下文中执行,因此您可以使用 $this 从 php 访问其方法。
在这种情况下,您想要的方法是 assignInScope($val, $scope)例如:
您还可以使用 readVar($name ),即:
That local variables are saved into an internal variable of the Dwoo object while the template is executed. The actual template code is executed within the Dwoo object's context, so you have access to its methods from php using $this.
The method you want in this case is assignInScope($val, $scope) that will assign it as such for example:
You can also read from it with readVar($name), i.e.: