繁体   English   中英

如何在ZF1中的命名空间内使用zend模型类

[英]How to use zend model class inside a namespace in ZF1

我在ZF1的我的模型文件夹之外创建了一个命名空间。 现在,我想在创建的名称空间中建立数据库连接,为此,我想使用现有的模型类。

创建模型类的对象时,其引发错误“找不到类”。

下面是示例

模型文件:

class Application_Model_Fetchdetails extends Zend_Db_Table_Abstract
{
    public function getDetails(){
        // model code here to fetch the data from database
    }
}

命名空间文件:

namespace Product\Fetch;
class fetchData  {

    function __construct() {
        $this->Obj = new Application_Model_Fetchdetails();
    }

    /**
     * function will fetch the data
     */
    public function getData()
    {
        try {
           $data = $this->Obj->getDetails("col","id='A1'");
           return $data;
        } catch(Zend_Exception $e) {
            echo "error".$e->getMessage(); die;
        }
    }

在创建对象说未找到类时,在getData函数和构造函数中显示错误

因为您使用Product\\Fetch为该类命名空间,所以它将自动为模型命名。 您需要添加以下内容:

namespace Product\Fetch;

use \Application_Model_Fetchdetails; // ADD THIS

class fetchData  {
   // ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM