如何在Phalcon视图中呈现代码 [英] How to render code in phalcon view

查看:351
本文介绍了如何在Phalcon视图中呈现代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$view->start();
$view->render("products", "list");
$view->finish();

上面显示了如何从文件进行渲染,我想知道是否可以使用此方法渲染字符串/代码?

above is show how to render from a file, I wonder is it possible to render a string/code with this method?

$view->start();
$view->renderstring("<?php echo $this->url->get('users/list') ?>");
$view->finish();

推荐答案

您可以使用'setContent'设置视图内容:

You can use 'setContent' to set the view content:

$view->setContent('<h1>hello</h1>');

但是此函数将最终内容接收到视图.因此,要正确使用此示例,请执行以下操作:

But this functions receives the final content to the view. So to do the example you gave the correct use would be:

$output = 'The link is: <a href="'.$this->url->get('users/list').'">link</a>';
$this->view->setContent( $output );
echo $this->view->getContent();

这篇关于如何在Phalcon视图中呈现代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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