在 Smarty 中使用 Recess 框架时如何指定 Content-type
我目前正在使用 PHP Recess 框架和 Smarty 模板引擎。在我的控制器中,我的代码类似于:
/**
* !View Smarty
* !RespondsWith Smarty
* !Prefix Views: templates/, Routes: /
*/
class XHomeController extends Controller {
/** !Route GET */
function index()
{
$this->title = "Some title...";
}
}
并且在相应的 Smarty 视图中,我像往常一样引用 {$title}
。
该视图在除 Android 浏览器(在我的 2.3 Nexus One、3.2 平板电脑以及 Android 模拟器上)之外的所有浏览器中都能正确呈现。我认为我已经将问题追溯到这样一个事实:Smarty 视图正在渲染并发送到没有内容类型的浏览器。
使用 http://web-sniffer.net/,我注意到响应中的内容类型为空。
使用Smarty时如何指定Recess中的Content-type?我尝试将 header('Content-type: text/html') 添加到控制器中的方法,但这不起作用。
知道我做错了什么吗?
I am currently using the PHP Recess framework with the Smarty templating engine. In my controller, I have code similar to:
/**
* !View Smarty
* !RespondsWith Smarty
* !Prefix Views: templates/, Routes: /
*/
class XHomeController extends Controller {
/** !Route GET */
function index()
{
$this->title = "Some title...";
}
}
and, in the corresponding Smarty view, I refer to {$title}
as usual.
The view renders correctly in all browsers except Android browsers (on my 2.3 Nexus One, on a 3.2 tablet as well as in the Android emulator). I think that I've traced the problem to the fact that the Smarty view is being rendered and sent to the browsers without a Content-type.
Using http://web-sniffer.net/, I notice that Content-type in the Response is empty.
How can I specify the Content-type in Recess when using Smarty? I've tried adding header('Content-type: text/html') to the method in the controller but this does not work.
Any idea of what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想在凹槽/框架/视图中查看 SmartyView 代码。该类应该有一个 canRespondWith() 方法,该方法将验证视图是否可以使用特定的 MIMEType 进行响应。例如:
如果返回 true,则将使用 XmlView。在 AbstractView 类中,sendHeaders() 方法将设置 Content-Type:
查看 escape/http/MimeTypes.class.php 以查看“xml”如何使用正确的标头进行响应。您还需要查看 SmartyView 以查看您返回的 mimetype,以了解将设置什么标头。
I would like to see the SmartyView code in recess/framework/views. That class should have a canRespondWith() method that will verify if a view can respond with a certain MIMEType. For example:
If this returns true, then the XmlView will be used. In the AbstractView class, the sendHeaders() method will set the Content-Type:
Look in recess/http/MimeTypes.class.php to see how 'xml' will respond with the correct headers. You also need to look in your SmartyView to see what mimetype you are returning to see what header will be set.