2014-06-25 80 views
0

我想在$表中顯示$ result的所有數據,但有一些錯誤。
該通知是 「數組到字符串轉換」
這裏的控制器:PHP Array to String轉換問題

public function actionIndex() 
    { 
     $command = Yii::app()->db->createCommand(' 
     Select username as user 
     From application_admin aa, application a 
     Where a.app_id = aa.app_id'); 
     $reader = $command->query(); 
     $dataUser = $reader->readAll(); 

    $dataProvider = Application::model()->findAll(); 

    foreach ($dataProvider as $data) { 
     $temp = array(); 
       $name = $data->name; 
       $customer = $dataUser; 
       $category = $data->appCategory->name; 

       $temp['name'] = $name; 
       $temp['customer'] = $customer; 
       $temp['category'] = $category; 
       $result[] = $temp; 
    } 

    $this->render('index',array('result'=>$result)); 
    } 

,這是觀:

<?php 
    $i=1; 
     foreach ($result as $data){ 
    ?> 
     <tr class="center clickableRow"> 
      <div> 
       <td><?php echo $i; ?></td> 
       <td><?php echo $data['name']; ?></td> 
       <td><?php echo $data['customer'];?></td> //error in this line 
       <td><?php echo $data['category'];?></td> 
      </div> 
     </tr > 

     <?php 
      $i++; 
     } 

    ?> 

請給我一些建議,謝謝

+0

'var_dump($ data ['customer'])'並檢查內容 – user1978142

+0

$ customer = $ dataUser [$ j];可能是$ dataUser [$ j]是一個數組.. ..!它是什麼..? –

+0

對不起,這是我的錯。我做了一些嘗試,忘記撤消,我使用$ j,因爲我認爲$ dataUser = $ reader-> readAll();將返回數組 – Ken

回答

0

最後我得到它

<td><?php echo $data['customer']['user'];?></td> 

謝謝所有