Publish ZF2 project on server with Cpanel

1

I have a project in my localhost that works impeccably, I uploaded the project to a cPanel server in Hostgator, I updated php to its version 7.0 so that everything works ok, I uploaded it to a folder and create a subdomain that points to the folder public

But when I enter the subdomain directly I get the following error:

  

Zend \ Mvc \ Controller \ ControllerManager :: createFromInvokable: failed retrieving "appscontrollerindex (alias: Apps \ Controller \ Index)" via invokable class "Apps \ Controller \ IndexController"; class does not exist

Then I try to go to the authentication driver and it throws me the following error:

Fatal error: Uncaught Error: Class 'Users\Model\Users' not found ...

- UPDATE 1 ---

In the Authentication module, so I define the controller in the file module.config.php :

'controllers' => array(
    'invokables' => array(
        'Authentication\Controller\Index' => 'Authentication\Controller\IndexController'
    ),
),

And in the file IndexController of the Authentication module, this line includes the Users class:

use Users\Model\Users;

And then within an action I call it like this:

$this->dbAdapter =$this->getServiceLocator()->get('Zend\Db\Adapter');
$users = new Users($this->dbAdapter);

- UPDATE 2 ---

I was doing everything possible because it worked, I contacted Hostagtor technical support and they told me that reseller and web plans are not compatible with ZF2 and that's why they did not work. So I'm looking for another server that even has a instructional for to install ZF2

    
asked by albertcito 18.08.2016 в 18:01
source

1 answer

1

Symptoms point ( for now ) to setting the getAutoloaderConfig() within Module.php .

But this usually throws errors if you use directory structures other than the classic skeleton and it has not been configured correctly.

Example:

Basic Structure

module
├── ModuleName
│   ├── config
│   │   └── module.config.php
│   ├── src
│   │   └── ModuleName
│   │       ├── Controller
│   │       │   └── IndexController.php
│   │       └── Model
│   │           └── MyModel.php
│   ├── view
│   └── Module.php
│...

Setting autoloader in Module.php

public function getAutoloaderConfig()
{
    return [
        'Zend\Loader\StandardAutoloader' => [
            'namespaces' => [
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ],
        ],
    ];
}

Theory

For a previous question I noticed that you had the type structure:

module
├── ModuleName
│   ├── config
│   │   └── module.config.php
│   ├── Controller
│   │   └── IndexController.php
│   ├── Model
│   │   └── MyModel.php
│   ├── view
│   └── Module.php
│...

So the autoloader setting in Module.php should look like this:

public function getAutoloaderConfig()
{
    return [
        'Zend\Loader\StandardAutoloader' => [
            'namespaces' => [
                __NAMESPACE__ => __DIR__,
            ],
        ],
    ];
}

I think you should check the configuration of each Module.php and check that they effectively point to the structure correctly so that the namespaces respond appropriately.

Coinciding with this, it may be the reason why you do not recognize the Users\Model\Users model.

Play the error in local

As an exercise if you want to check the error in the local application that you have, in any Module.php try to change:

public function getAutoloaderConfig()
{
    return [
        'Zend\Loader\StandardAutoloader' => [
            'namespaces' => [
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ],
        ],
    ];
}

By:

public function getAutoloaderConfig()
{
    return [
        'Zend\Loader\StandardAutoloader' => [
            'namespaces' => [
                'OtroNamespace' => __DIR__ . '/src/' . __NAMESPACE__,
            ],
        ],
    ];
}

I should give the same error for the one you are asking.

    
answered by 19.08.2016 / 10:56
source