Php Zend Framework 2模块索引内容未呈现
我已经在我的ZF2应用程序中创建了一个客户机模块,并且正在按照中的建议使用ServiceManager。我的模型课如下:Php Zend Framework 2模块索引内容未呈现,php,doctrine-orm,zend-framework2,Php,Doctrine Orm,Zend Framework2,我已经在我的ZF2应用程序中创建了一个客户机模块,并且正在按照中的建议使用ServiceManager。我的模型课如下: <?php namespace Client\Model; class Client { public $id; public $familyname; public $businessname; public function exchangeArray($data) { $this->id =(!empty(['id'])) ? $data['i
<?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;
}
}
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> </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>
}
我的ClientController.php
如下:
<?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;
}
}
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> </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>
最后但并非最不重要的一点是,view类如下所示:
<?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;
}
}
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> </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
的内容正在呈现。但是,my/module/client/view/client/client
中的index.phtml
包含用于添加或编辑未呈现的客户端的标记
更新2:我没有提到我使用骨架应用程序作为这个应用程序的基础。不确定是否存在导致我的问题的配置更改
更新3:我启动这个应用程序的目的是使用doctrine2orm。然而,已经决定只使用ZendDbAdpater。我从应用程序配置中删除了ORM。我的问题可能是由项目中的残余条令代码引起的吗?如果是这样,需要删除哪些文件和文件夹才能从应用程序中完全删除条令2?
<?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> </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);} ?>
姓
企业名称
您所说的“不渲染”是什么意思?你有空白页吗?404页?