Zend Framework 2:如何使用我的Abtract模型扩展模型?

时间:2014-06-03 03:52:41

标签: zend-framework2

我有一个结构项目:https://docs.google.com/file/d/0B6hBvUW6YcomNHZJYUxvbTgxNkE

这是我的AbstractTable.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;
}
}

这是我的CategoryTable.php:

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.

如何修复此错误?谢谢!

1 个答案:

答案 0 :(得分:0)

ZF2引用主机根文件夹中的所有文件,尝试创建子域并复制文件并访问页面