Yii PHP可恢复错误

时间:2012-01-17 15:45:01

标签: php yii

我使用的是Yii PHP框架,但我不能写这段代码,这是真的吗?

<?php 
if ( Yii::app()->user->isGuest != 1 ){ 
$guest =  "<div class='box admin'>" .
$this->beginWidget('zii.widgets.CPortlet', array(
            'title'=>'Admin menu',
        ));
        $this->widget('zii.widgets.CMenu', array(
            'items'=>$this->menu,
            'htmlOptions'=>array('class'=>'operations'),
        ));
        $this->endWidget();

"</div>";
}
 else { $guest = ""; };
?>

<?php

echo $guest;

?>

错误消息:

Recoverable error

3 个答案:

答案 0 :(得分:1)

在此行的末尾需要一个分号:

$guest =  "<div class='box admin'>"

答案 1 :(得分:1)

我只在这里猜测,但这段代码可能有效:

<?php 
if ( Yii::app()->user->isGuest != 1 ){ 
  $guest = '<div class="box admin">'
    . $this->beginWidget('zii.widgets.CPortlet', array(
      'title'=>'Admin menu',
    ))
    . $this->widget('zii.widgets.CMenu', array(
      'items'=>$this->menu,
      'htmlOptions'=>array('class'=>'operations'),
    ))
    . $this->endWidget()
    . '</div>';
}
else
  $guest = '';
?>

<?php

echo $guest;

?>

答案 2 :(得分:0)

我只是删除使用此代码而没有变量,我在地方重写代码

<?php 
if ( Yii::app()->user->isGuest != 1 ){ 
  echo '<div class="box admin">';
    $this->beginWidget('zii.widgets.CPortlet', array(
      'title'=>'Admin menu',
    ));
    $this->widget('zii.widgets.CMenu', array(
      'items'=>$this->menu,
      'htmlOptions'=>array('class'=>'operations'),
    ));
    $this->endWidget();
    echo '</div>';
} ?>