Problma com Zend "ServiceNotFoundException"
Se alguem souber onde errei..gostaria de ajuda.. obrigado
Erro e Log:
An error occurred
An error occurred during execution; please try again later.
Additional information:
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:496
Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Zend\Db\Adapter\Adapter
Stack trace:
#0 D:\wamp\www\CursoZF2\module\Livraria\Module.php(34): Zend\ServiceManager\ServiceManager->get('Zend\Db\Adapter...')
#1 [internal function]: Livraria\Module->Livraria\{closure}(Object(Zend\ServiceManager\ServiceManager), 'livrariamodelca...', 'Livraria\Model\...')
#2 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(853): call_user_func(Object(Closure), Object(Zend\ServiceManager\ServiceManager), 'livrariamodelca...', 'Livraria\Model\...')
#3 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(985): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'livrariamodelca...', 'Livraria\Model\...')
#4 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(598): Zend\ServiceManager\ServiceManager->createFromFactory('livrariamodelca...', 'Livraria\Model\...')
#5 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(557): Zend\ServiceManager\ServiceManager->doCreate('Livraria\Model\...', 'livrariamodelca...')
#6 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(481): Zend\ServiceManager\ServiceManager->create(Array)
#7 D:\wamp\www\CursoZF2\module\Livraria\src\Livraria\Controller\IndexController.php(12): Zend\ServiceManager\ServiceManager->get('Livraria\Model\...')
#8 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): Livraria\Controller\IndexController->indexAction()
#9 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#10 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#11 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#13 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#14 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#15 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#16 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 D:\wamp\www\CursoZF2\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#18 D:\wamp\www\CursoZF2\public\index.php(12): Zend\Mvc\Application->run()
#19 {main}
Classes:
Glogal.php
<?php
return array(
'db'=>array(
'driver'=>'Pdo',
'dsn'=>'mysql:dbname=zf2_livraria;host=localhost',
'driver_options'=>array(
PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES \'UTF-8\''
)
),
'service_mananger'=>array(
'factories'=>array(
'Zend\Db\Adapter\Adapter'=>'Zend\Db\Adapter\AdapterServiceFactory'
)
)
);
Classe Local.php:
<?php
return array(
'db'=>array(
'username'=>'root',
'password'=>''
)
);
Classe Module:
<?php
namespace Livraria;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Livraria\Model\CategoriaTable;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getServiceConfig(){
return array(
'factories'=>array(
'Livraria\Model\CategoriaService'=>function($service){
$dbAdapter=$service->get('Zend\Db\Adapter\Adapter');
$categoriaTable=new CategoriaTable($dbAdapter);
$categoriaService = new Model\CategoriaService($categoriaTable);
return $categoriaService;
}
)
);
}
}
IndexController:
<?php
namespace Livraria\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$categoriaService=$this->getServiceLocator()->get('Livraria\Model\CategoriaService');
$categorias=$categoriaService->fetchAll();
return new ViewModel(array('categorias'=>$categorias));
}
}
Categoria:
<?php
namespace Livraria\Model;
class Categoria {
public $id;
public $nome;
public function exchangeArray($data){
$this->id=(isset($data['id']))?$data['id']:null;
$this->id=(isset($data['nome']))?$data['nome']:null;
}
}CategoriaTable:
<?php
namespace Livraria\Model;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
class CategoriaTable extends AbstractTableGateway {
protected $table="categorias";
public function __construct(Adapter $adapter){
$this->adapter=$adapter;
$this->resultSetPrototype=new ResultSet();
$this->resultSetPrototype->setArrayObjectPrototype(new Categoria());
$this->initialize();
}
}CategoriaService:
<?php
namespace Livraria\Model;
class CategoriaService {
/**
* @var Livraria\Model\CategoriaTable
*/
protected $categoriaTable;
public function __construc(CategoriaTable $table){
$this->categoriaTable = $table;
}
public function fetchAll(){
$resultSet = $this->categoriaTable->select();
return $resultSet;
}
}
nao sei mas andei pesquisando vi em um forum americano algo parecido o pessoal tava falando q o problema era no server.. sera q meu caso é o mesmo?
Discussão (1)
Carregando comentários...