天生我才必有用

Symfony Template系统内建的一些常用变量

Posted in PHP    作者:Ray    2007年十月14日

在Symfony Template的系统中有一些经常使用的内建对象,这项可以减轻Model的处理程序中的一些负担,而不需把任何简单的变量都必须先赋值给View,而View中再次使用赋值变量来显示.而让Template可以直接把一些简单变量显示在页面中.

1. $sf_context: The whole context object (instance of sfContext)

2. $sf_request: The request object (instance of sfRequest)

3. $sf_params: Parameters of the request

4. $sf_user: The current user session object (instance of sfUser)

简单的代码:

// Long version
<?php echo $sf_request->getParameter(‘total’); ?>

// Shorter version
<?php echo $sf_params->get(‘total’); ?>

// Equivalent to the following action code
echo $this->getRequestParameter(‘total’);

Leave a Reply