Zend framework2 Zend Framework 2:如何使用Abtract模型扩展模型?
我有一个具有以下结构的项目: 这是我的AbstractTable.php:Zend framework2 Zend Framework 2:如何使用Abtract模型扩展模型?,zend-framework2,Zend Framework2,我有一个具有以下结构的项目: 这是我的AbstractTable.php: namespace AdminManage\Model; use Zend\Db\Adapter\Adapter; use Zend\ServiceManager\ServiceLocatorInterface; class AbstractTable{ protected $tablegateway; protected $table; protected $serviceLocator; protected $ada
namespace AdminManage\Model;
use Zend\Db\Adapter\Adapter;
use Zend\ServiceManager\ServiceLocatorInterface;
class AbstractTable{
protected $tablegateway;
protected $table;
protected $serviceLocator;
protected $adapter;
public function __construct(TableGateway $tableGateway) {
$this->tableGateway = $tableGateway;
$this->table = $this->tableGateway->getTable();
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator){
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator(){
return $this->serviceLocator;
}
public function setDbAdapter(Adapter $adapter){
$this->adapter = $adapter;
return $this;
}
public function getDbAdapter(){
return $this->adapter;
}
public function fetchAll(){
return $this->tablegateway->select();
}
public function getTable(){
if(!$this->table)
$this->table = $this->tableGateway->getTable();
return $this->table;
}
}
namespace Category\Model;
use Zend\Db\Sql\Sql;
use AdminManage\Model\AbstractTable;
class CategoryTable extends AbstractTable {
public function getListCategory() {
$adapter = $this->getDbAdapter ();
$sql = new Sql ( $adapter );
$select = $sql->select ( array (
"c" => "category"
) )->join ( array (
"cd" => "category_description"
), "c.category_id = cd.category_id" );
echo $sql->prepareStatementForSqlObject ( $select )->getSql ();
}
}
这是我的CategoryTable.php:
namespace AdminManage\Model;
use Zend\Db\Adapter\Adapter;
use Zend\ServiceManager\ServiceLocatorInterface;
class AbstractTable{
protected $tablegateway;
protected $table;
protected $serviceLocator;
protected $adapter;
public function __construct(TableGateway $tableGateway) {
$this->tableGateway = $tableGateway;
$this->table = $this->tableGateway->getTable();
}
public function setServiceLocator(ServiceLocatorInterface $serviceLocator){
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator(){
return $this->serviceLocator;
}
public function setDbAdapter(Adapter $adapter){
$this->adapter = $adapter;
return $this;
}
public function getDbAdapter(){
return $this->adapter;
}
public function fetchAll(){
return $this->tablegateway->select();
}
public function getTable(){
if(!$this->table)
$this->table = $this->tableGateway->getTable();
return $this->table;
}
}
namespace Category\Model;
use Zend\Db\Sql\Sql;
use AdminManage\Model\AbstractTable;
class CategoryTable extends AbstractTable {
public function getListCategory() {
$adapter = $this->getDbAdapter ();
$sql = new Sql ( $adapter );
$select = $sql->select ( array (
"c" => "category"
) )->join ( array (
"cd" => "category_description"
), "c.category_id = cd.category_id" );
echo $sql->prepareStatementForSqlObject ( $select )->getSql ();
}
}
在控制器中调用getListCategory()时,出现错误:
Fatal error: Class 'AdminManage\Model\AbstractTable' not found in D:\xampp\htdocs\dokusyu\htdocs\admin\dokusyu_be\module\Course\src\Category\Model\CategoryTable.php on line 5.
如何修复此错误?谢谢大家! ZF2引用主机根文件夹中的所有文件,尝试创建子域并复制文件并访问页面