热搜:NVER node 开发 php

PHP补基础

2024-09-18 18:20:01
PHP补基础

近期在看YII

public $template='{view} {update} {delete}';

以上这种写法,如何单独输出{view},{update}呢
同时以下代码片段还会报错
foreach(array('view','update','delete') as $id)		{			$button=array(				'label'=>$this->{$id.'ButtonLabel'},				'url'=>$this->{$id.'ButtonUrl'},				'imageUrl'=>$this->{$id.'ButtonImageUrl'},				'options'=>$this->{$id.'ButtonOptions'},			);			if(isset($this->buttons[$id]))				$this->buttons[$id]=array_merge($button,$this->buttons[$id]);			else				$this->buttons[$id]=$button;		}

报错提示:Fatal error: Using $this when not in object context in D:\Wamp\Apache\htdocs\1.01\this.php on line 9


回复讨论(解决方案)

public $template='{view} {update} ';
不久可以单独输出view和update了么?

<?php    $template='{view} {update} {delete}';    echo $template;  ?>

output:
{view} {update} {delete}

<?php    $template='{view} {update} {delete}';    echo $template;  ?>

output:
{view} {update} {delete}

view ,update,delete 分别对应yii grid中的查看按钮,更新按钮和删除按钮组件,需要哪个就加哪个。
比如,只需要view按钮:
$template='{view}';

这个我也知道的,我想知道如何单独输出view,update啊