I am learning the framework Zend 2. I am stuck on a error which says that the system can't find the model class. Below here the message.
Fatal error: Class 'Album\\Model\\Album' not found in /Applications/MAMP/htdocs/zend2_tut/module/Album/Module.php on line 47
The code I used is from the tutorial from zend 2.
Codes are below here:
Module.php
namespace Album;
// Models
use Album\Model\Album;
use Album\Model\AlbumTable;
// Db
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
// Zend
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
public function getAutoloaderConfig() {
return array(
'Zend\Loader\ClassMapAutoloader' => array (
__DIR__ . '/autoload_classmap.php'
),
'Zend\Loader\StandardAutoloader' => array (
'namespaces' => array (
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
)
)
);
}
public function getConfig() {
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig() {
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
Album.php
namespace Album\Model;
class Album
{
public $id;
public $artist;
public $title;
public function exchangeArray($data) {
$this->id = (!empty($data["id"])) ? $data["id"] : null;
$this->artist = (!empty($data["artist"])) ? $data["artist"] : null;
$this->title = (!empty($data["title"])) ? $data["title"] : null;
}
}
Below the file tree
Album
Model
------
Album.php
Module.php
I hope I can solve this because I don't know where the issue is. Thanks in advance.
I think in Module.php you need to do this below change
class Module implements AutoloaderProviderInterface, ConfigProviderInterface {
To
class Module {
You no need to add these to link as well
use Zend\\ModuleManager\\Feature\\AutoloaderProviderInterface; use Zend\\ModuleManager\\Feature\\ConfigProviderInterface;
without these feature autoloader libraries you module will work fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.