[ZF 2.2.5] - Getadapter null
Bonjour la communauté,
J'ai un souci sur un nouveau projet.
Dans le module Application, au moment d'exécuter une requête j'ai une erreur. En effectuant un "vardump" sur le $this->getAdapter() j'ai NULL.
Comme s'il n'arrivait pas à se connecter à la BDD ?
En sachant que sur un autre projet (autre hébergeur aussi), aucun problème.
Les scripts :
global.php et local.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'pgsql:dbname=nombase;port=5432;host=localhost'
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
); |
Code:
1 2 3 4 5 6
| return array(
'db' => array(
'username' => 'user_base',
'password' => 'mdpbase',
),
); |
IndexController
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| namespace Application\Controller;
use Zend\View\Renderer\PhpRenderer;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
@session_start();
class IndexController extends AbstractActionController
{
public function indexAction()
{
$list = $this->getApplicationTable()->fetchAll();
return new ViewModel(array(
'liste' => $list,
));
}
public function getApplicationTable()
{
if (!$this->applicationTable) {
$sm = $this->getServiceLocator();
$this->applicationTable = $sm->get('Application\Model\ApplicationTable');
}
return $this->applicationTable;
}
} |
ApplicationTable
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
namespace Application\Model;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Where;
class ApplicationTable extends AbstractTableGateway
implements \Zend\Db\Adapter\AdapterAwareInterface
{
protected $table = 't_page';
public function setDbAdapter(Adapter $adapter)
{
$this->adapter = $adapter;
$this->resultSetPrototype = new HydratingResultSet();
$this->resultSetPrototype->setObjectPrototype(new Application());
$this->initialize();
}
public function fetchAll($query = 0)
{
var_dump($this->getAdapter());
} |
Module.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use Application\Model\Application;
use Application\Model\ApplicationTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
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 getServiceConfig()
{
return array(
'factories' => array(
'Application\Model\ApplicationTable' => function($sm) {
$tableGateway = $sm->get('ApplicationTableGateway');
$table = new ApplicationTable($tableGateway);
return $table;
},
'ApplicationTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Application());
return new TableGateway('t_page', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
public function getApplicationTable()
{
if (!$this->applicationTable) {
$sm = $this->getServiceLocator();
$this->applicationTable = $sm->get('Application\Model\ApplicationTable');
}
return $this->applicationTable;
}
} |
Comment puis-je debugger ce getAdapter ?
Merci par avance,