略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Yaf_View_Simple::assign

2024-04-27

Yaf_View_Simple::assign

(Yaf >=1.0.0)

Yaf_View_Simple::assign为视图引擎分配一个模板变量

说明

public Yaf_View_Simple::assign(string $name, mixed $value = ?): bool

为视图引擎分配一个模板变量

参数

name

字符串或者数组

如果为字符串, 则$value不能为空

value

mixed value

返回值

范例

示例 #1 Yaf_View_Simple::assign()example

<?php
class IndexController extends Yaf_Controller_Abstract {
    public function 
indexAction() {
        
$this->getView()->assign("foo""bar");
        
$this->_view->assign( array( "key" => "value""name" => "value"));
    }
?>

示例 #2 template()example

<html>
 <head>
  <title><?php echo $foo?></title>
 </head>  
<body>
  <?php 
    
foreach ($this->_tpl_vars as $name => value) {
         echo $
$name// or echo $this->_tpl_vars[$name];
    
}
  
?>
</body>
</html>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/yaf-view-simple.assign.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3