2014-04-23 53 views
0

我无法使用yii框架列出网格中的数据。我的控制器是Sitecontroller.php,我的看法是list_jobseeker.phpYii:无法在网格视图中显示数据

我得到了错误:

Parse error: syntax error, unexpected '*', expecting ']' in C:\wamp\www\yii_new\framework\base\CComponent.php(612) : eval()'d code on line 1

任何人提供任何建议,纠正这些问题?

我的控制器:

public function actionlist_jobseeker() 
    { 
    $session_id=Yii::app()->session['user_id']; 
    if ($session_id == "") 
    { 
     $this->redirect(array('/employee/site/login')); 
    } 
    $user_id =$session_id; 
    $items = Yii::app()->db->createCommand() 
    ->select('*') 
    ->from('job_seeker_profile s') 
    ->join('job_profile j','s.user_id = j.user_id') 
    ->order('s.id') 
    ->queryAll(); 
    $this->render('list_jobseeker',array('items' =>$items)); 
} 

我的视图页面 - list_jobseeker.php

<h1>View Jobseeker</h1> 

<div class="flash-success"> 

</div> 

<div class="form"> 
<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'rates-phase-grid', 
    'htmlOptions' => array('class' => 'table table-striped table-bordered table-hover'), 
    'dataProvider'=>new CArrayDataProvider($items), 
    'columns' => array(
     array(
      'name' => 'Name', 
      'type' => 'raw', 
      'value' => 'CHtml::encode($data[*]->name)', 
      'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz'), 

    ), 
     array(
      'name' => 'Email', 
      'type' => 'raw', 
      'value' => 'CHtml::encode($data[*]->email)', 
      'htmlOptions' => array('style'=>'width:250px;','class'=>'zzz') 

     ), 
     array(
      'name' => 'Password', 
      'type' => 'raw', 
      'value' => 'CHtml::encode($data[*]->password)', 
      'htmlOptions' => array('style'=>'width:90px;','class'=>'zzz') 
     ), 
     array(
      'name' => 'Contact No', 
      'type' => 'raw', 
      'value' => 'CHtml::encode($data[*]->contact_no)', 
      'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz') 

     ), 
     array(
      'name' => 'Gender', 
      'type' => 'raw', 
      'value' => 'CHtml::encode($data[*]->gender)', 
      'htmlOptions' => array('style'=>'width:40px;','class'=>'zzz') 

     ), 


     array(
      'class' =>'CButtonColumn', 
      'deleteConfirmation'=>'Are you sure you want to delte this item?', 
      'template'=>'{update}{delete}', 

      'buttons' =>array('update'=>array(

      'label'=>'edit', 
    'url'=>'Yii::app()->controller->createUrl("UpdateJob",array("id"=>$data["id"]))', 

       ), 
      'delete'=>array('label'=>'delete', 
    'url'=>'Yii::app()->controller->createUrl("DeleteJob",array("id"=>$data["id"]))'), 

       ) 
      ) 
     ), 
)); 
?> 

</tbody> 

+0

你知道这应该如何工作'$ data [*] - > name'? – Jurik

+0

不,我得到了这些代码从我的prevoius stackoverflow张贴。我得到了这些页面显示4的4结果。 名称\t电子邮件“。但我有错误”解析错误:语法错误,意外'*',期待']'在C:\ wamp \ www \ yii_new \ framework \ base \ CComponent.php(612):eval()'d代码在线1“ – user3514095

回答

0

改变所有的[*]

$data[*]->name 

匹配列

$data["name"] 
+0

当我给名称单引号即'名称'显示错误我的代码在Dreamweaver – user3514095

+0

尝试双重,你得到的主意!你必须使用数据作为数组,而不是对象 – tinybyte

+0

嗨tinybyte..Now我有这些错误“未定义索引:名称 C:\ wamp \ www \ yii_new \ framework \ base \ CComponent.php(612):eval ()'d code(1)“ – user3514095