简体   繁体   English

找不到Zend Framework 2模型类别

[英]Zend Framework 2 model class not found

I have a model in src\\Front\\Model\\FrontModel.php 我在src \\ Front \\ Model \\ FrontModel.php中有一个模型

I am trying to extend it in my IndexController i have this in my Module.php: 我想在我的IndexController中扩展它,我在Module.php中有它:

use Front\\Model\\FrontModel;

But i always get this error: 但是我总是得到这个错误:

Fatal error: Class 'Front\\Model\\FrontModel' not found in 致命错误:找不到类'Front \\ Model \\ FrontModel'

C:\\Apache24\\htdocs\\cartbiz\\module\\Front\\src\\Front\\Controller\\IndexController.php on line 16 C:\\ Apache24 \\ htdocs \\ cartbiz \\ module \\ Front \\ src \\ Front \\ Controller \\ IndexController.php在第16行

I have this in my IndexController where i am trying to extend my model my Controller resides in src\\Front\\Controller\\IndexController.php 我在我想扩展我的模型的IndexController中有这个,我的Controller驻留在src \\ Front \\ Controller \\ IndexController.php中

namespace Front\Controller;
use Front\Model\FrontModel;

class IndexController extends FrontModel
{


/* Initialize Controller */

public function initAction()
{
    parent::initAction();
}
}

I have this as my model class my model class resides in src\\Front\\Model\\FrontModel.php 我有这个作为我的模型类,我的模型类驻留在src \\ Front \\ Model \\ FrontModel.php中

namespace Front\Model\FrontModel;   
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class FrontModel extends AbstractActionController
{

    /* Application initializer 
    ** All front application logic
    */

    public function __construct ()
    {
        die('ssss');

        $this->_viewManager=new ViewModel;
        $this->_viewManager->setTemplate('front/index/index');
        return $this->_viewManager;


    }
}

Any help is appreciated 任何帮助表示赞赏

You need to add a namespace to the FontModel class. 您需要向FontModel类添加namespace

namespace Front\Model;

use Zend\Mvc\Controller\AbstractActionController;

class FrontModel extends AbstractActionController
{}

Also, it's worth noting that your naming conventions could lead to confusion. 另外,值得注意的是,您的命名约定可能导致混乱。 I would recommend placing all the controllers in the controller folder, and reading up on the coding standards . 我建议将所有控制器放在controller文件夹中,并阅读编码标准

Tested and works 经过测试和工作

namespace Front\Model;

use Zend\Mvc\Controller\AbstractActionController;

class FrontModel extends AbstractActionController
{

    /* Application initializer 
    ** All front application logic
    */

    public function __construct ()
    {
        die('ssss');

        $this->_viewManager=new ViewModel;
        $this->_viewManager->setTemplate('front/index/index');
        return $this->_viewManager;


    }
}

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

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