Reputation: 57
I followed every step of the Get Started tutorial on ZF2 website ( http://framework.zend.com/manual/current/en/user-guide/database-and-models.html ).
I've searched on this website (and google of course) possible solutions. I'm not gonna lie, there are thousands of questions that look like these EXCEPT all solution given don't seem to work.
These are the error codes : (sorry for the format) ( ! ) Fatal error: Class 'Action\Model\ActionTable' not found in C:\wamp\www\zf2\module\Action\Module.php on line 46
<?php
/**
* ZF2 uses ModuleManager to load and configure a module. To do that, it will look up for this class in the root of the module directory.
*/
namespace Action;
use Action\Model\ActionTable;
use Action\Model\Action;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
/**
* Class Module is expected by ZF2.
*/
class Module {
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(
'Action\Model\ActionTable' => function($sm) {
$tableGateway = $sm->get('ActionTableGateway');
$table = new ActionTable($tableGateway);
return $table;
},
'ActionTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Action());
return new TableGateway('action', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
?>
<?php
namespace Action\Model;
use Zend\Db\TableGateway\TableGateway;
class AlbumTable
{
protected $tableGateway;
/**
* TableGateway is an object that represents a table in a database.
*/
public function __construct(TableGateway $tableGateway)
{
$this->tableGateway = $tableGateway;
}
/**
* fetchAll function
* retrieves all rows from the database
* @return ResultSet containing all rows of the database.
*/
public function fetchAll()
{
$resultSet = $this->tableGateway->select();
return $resultSet;
}
/**
* getAction function
* retrieves a single row from the database using the id
* @param $id (int)
* @return $row of error in exception
*/
public function getAction($id)
{
$id = (int) $id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if (!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}
/**
* saveAction function
* Creates a new row in the database or updates a row that already exists
* @param Action
* print Exception if error
*/
public function saveAction(Action $action)
{
$data = array(
'Num_action'=> $action-> $act_num,
'libelle_action'=> $action-> $act_label,
);
$id = (int) $action->id;
if ($id == 0) {
$this->tableGateway->insert($data);
} else {
if ($this->getAction($id)) {
$this->tableGateway->update($data, array('id' => $id));
} else {
throw new \Exception('Action id does not exist');
}
}
}
/**
* deleteAction function
* removes a row completely
* @param $id
*/
public function deleteAction($id)
{
$this->tableGateway->delete(array('id' => (int) $id));
}
}
?>
The architecture is good, the file are at the place they are said to be, i've tried adding \Action\Model\ before the ActionTable($tableGateway)... Nothing seems to work.
Anyone as any idea ??
Thank you very much for ANY clue, ANY lead, you could give me.
Upvotes: 0
Views: 48
Reputation: 33148
In ActionTable.php
on line 6:
class AlbumTable
presumably should be
class ActionTable
everything else looks good.
Upvotes: 1