2014-11-05 74 views
0

我在我的ZF2應用程序中創建了一個客戶端模塊,並按照ZF2 Read The Docs中的建議使用ServiceManager。我的模型類如下:Zend Framework 2模塊索引內容沒有渲染

<?php 
namespace Client\Model; 
class Client 
{ 
public $id; 
public $familyname; 
public $businessname; 

public function exchangeArray($data) 
{ 
    $this->id =(!empty(['id'])) ? $data['id'] : null; 
    $this->familyname=(!empty(['familyname'])) ? $data['familyname'] : null; 
    $this->businessname(!empty(['businessname'])) ? $data['businessname'] : null; 
} 
} 

ClientTable.php包含:

namespace Client\Model; 

use Zend\Db\TableGateway\TableGateway; 

class ClientTable 
{ 
    protected $tableGateway; 

    public function __construct(TableGateway $tableGateway) 
    { 
     $this->tableGateway = $tableGateway; 
    } 

    public function fetchAll() 
    { 
     $resultSet = $this->tableGateway->select(); 
     return $resultSet; 
    } 

    public function getClient($id) 
    { 
     $id = (int) $id; 
     $rowset = $this->tableGateway->select(array('id' => $id)); 
     $row = $rowset->current(); 
     if (!$row) { 
      throw new \Exception("Could not find row $id"); 
     } 
     return $row; 
    } 

    public function saveClient(Client $client) 
    { 
     $data = array(
      'familyname' => $client->familyname, 
      'businessname' => $client->businessname, 
     ); 

     $id = (int) $client(id); 
     if($id==0){ 
      $this->tableGateway->insert($data); 
     } else { 
     if($this->getClient($id)){ 
      $this->tableGateway->update($data, array('id' => $id)); 
     } else { 
      throw new \Exception('Client id does not exist'); 
     } 
    } 
} 

}

ClientController.php如下:

namespace Client\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Helper\ViewModel; 

class ClientController extends AbstractActionController 
{ 
protected $clientTable; 

public function getClientTable() 
{ 
    if(!$this->clientTable){ 
     $sm = $this->getServiceLocator(); 
     $this->clientTable = $sm->get('Client\Model\ClientTable'); 
    } 
    return $this->clientTable; 
} 

public function indexAction() 
{ 
    return new ViewModel(array(
     'client' => $this->clientTable->fetchAll(), 
    )); 
} 

public function addAction() 
{ 
    return array(); 
} 

public function editAction() 
{ 
    return array(); 
}  

} 

最後但並非最不重要的,視圖分類如下:

<?php 
$title = 'Client List'; 
$this->headtitle($title); 
?> 

<h1><?php echo $this->escapeHtml($title); ?></h1> 
<p> 
<a href="<?php echo $this->url('client', array('action'=>'add'));?>">Add New Client</a> 
</p> 

<table class="table"> 
<tr> 
<th>Family Name</th> 
<th>Business Name</th> 
<th>&nbsp;</th> 
</tr> 

<?php foreach ($client as $client) : ?> 
<tr> 
<td><?php echo $this->escapehtml($client->familyname);?></td> 
<td><?php echo $this->escapehtml($client->busienssname);?></td> 
<td> 
<a href="<?php echo $this->url('client', array('action'=>'edit', 
'id'=>$client->$id));?>">Edit</a> 
</td> 
</tr> 
<?php endforeach; ?> 
</table> 

我已將客戶端模塊添加到application.config.php。有人可以建議一些方法來解決我的問題,其中客戶端索引視圖不呈現?

更新:請注意,layout.phtml的內容正在渲染。但是,我的/module/client/view/client/client中的index.phtml包含用於添加或編輯未呈現的客戶端的標記。

更新2:我沒有提到我使用骨架應用程序作爲此應用程序的基礎。不知道是否有導致我的問題的配置更改?

更新3:我開始這個應用程序的目的是使用Doctrine2 ORM。但是,它已經決定改用ZendDbAdpater。我從應用程序配置中刪除了Doctrine ORM。我的問題是否可以由項目中的殘餘原則代碼引起?如果是這樣,需要刪除哪些文件和文件夾才能從應用程序中徹底刪除Doctrine 2?

+2

什麼意思是「不渲染」?你有空白頁嗎?一個404頁面? – 2014-11-05 20:51:24

回答

0
<?php foreach ($client as $client) : ?> 

您再次使用相同的變量。

您的視圖腳本可能有問題。你可以將它們包裝在一個try塊中並查看錯誤。

<?php 

try { 
    $title = 'Client List'; 
    $this->headtitle($title); 
?> 
<h1><?php echo $this->escapeHtml($title); ?></h1> 
<p> 

<a href="<?php echo $this->url('client', array('action'=>'add'));?>">Add New Client</a> 

</p> 


<table class="table"> 
    <tr> 
     <th>Family Name</th> 
     <th>Business Name</th> 
     <th>&nbsp;</th> 
    </tr> 
<?php foreach ($client as $client) : ?> 
    <tr> 
     <td><?php echo $this->escapehtml($client->familyname);?></td> 
     <td><?php echo $this->escapehtml($client->busienssname);?></td> 
     <td> 
      <a href="<?php echo $this->url('client', array('action'=>'edit', 
       'id'=>$client->$id));?>">Edit</a> 
     </td> 
    </tr> 
<?php endforeach; ?> 
</table> 

<?php } catch (\Exception $e) {var_dump($e);} ?>