1
votes

I have a model in src\Front\Model\FrontModel.php

I am trying to extend it in my IndexController i have this in my Module.php:

use Front\Model\FrontModel;

But i always get this error:

Fatal error: Class 'Front\Model\FrontModel' not found in

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

I have this in my IndexController where i am trying to extend my model my Controller resides in 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

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

2
What is the namespace statement written in the src\Front\Model\FrontModel.php file? i.e. above the class FrontModel extends AbstractActionController line.Kunal Dethe
sorry please see my edit now :)Pradeep Srivastava
i don't get the point of your above implementationdixromos98
Actually i want to create a global model for my front module in which their are various sub controllers like index controller for homepage for controlling the frontend of my application Front model can instantiate the Application necessary things like header, footer widgets if any etcPradeep Srivastava
Look at @AlexP's answer. The error you get is because of your namespaces are not right. FrontModel class is using the namespace Front\Model\FrontModel while it should be Front\Model your controller is looking for Front\Model\FrontModel class but with your setup you should: use Front\Model\FrontModel\FrontModel in your controller as it doesn't know the class, since you're currently using a namespace. I'm not creating a new answer as @AlexP is already covering it.Kwido

2 Answers

2
votes

You need to add a namespace to the FontModel class.

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.

0
votes

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;


    }
}