-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"no instance returned" Zend Framework 2 #3125
Comments
#262 again :)
…On Mon, Mar 6, 2017 at 6:48 PM, monteiro07 ***@***.***> wrote:
Hi, i have been following step by step the beginners guide of Zend
Framework 2 on their website (https://framework.zend.com/
manual/2.4/en/in-depth-guide/preparing-db-backend.html) and i encountered
the following error:
An exception was raised while creating "Blog\Controller\List"; no instance
returned
here is my module.config:
<?php // Filename: /module/Blog/config/module.config.php return array( //
This lines opens the configuration for the RouteManager 'db' => array(
'driver' => 'Pdo', 'username' => 'root', //edit this 'password' => '',
//edit this 'dsn' => 'mysql:dbname=blog;host=localhost', 'driver_options'
=> array( \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ) ),
'router' => array( // Open configuration for all possible routes 'routes'
=> array( // Define a new route called "post" 'post' => array( 'type' =>
'literal', // Configure the route itself 'options' => array( // Listen to
"/blog" as uri 'route' => '/blog', 'defaults' => array( 'controller' =>
'Blog\Controller\List', 'action' => 'index', ) ) ) ) ), 'controllers' =>
array( 'factories' => array( 'Blog\Controller\List' => 'Blog\Factory\ListControllerFactory'
) ), 'view_manager' => array( 'template_path_stack' => array( __DIR__ .
'/../view', ), ), 'service_manager' => array( 'factories' => array(
'Blog\Mapper\PostMapperInterface' => 'Blog\Factory\ZendDbSqlMapperFactory',
'Blog\Service\PostServiceInterface' => 'Blog\Factory\PostServiceFactory',
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory' ) ),
);
my listcontroller:
`<?php
// Filename: /module/Blog/src/Blog/Controller/ListController.php
namespace Blog\Controller;
use Blog\Service\PostServiceInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class ListController extends AbstractActionController
{
/**
* @var <https://github.com/var> \Blog\Service\PostServiceInterface
*/
protected $postService;
public function __construct(PostServiceInterface $postService)
{
$this->postService = $postService;
}
public function indexAction()
{
return new ViewModel(array(
'posts' => $this->postService->findAllPosts()
));
}
}my ListControllerFactory:<?php
// Filename: /module/Blog/src/Blog/Factory/ListControllerFactory.php
namespace Blog\Factory;
use Blog\Controller\ListController;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class ListControllerFactory implements FactoryInterface
{
/**
* Create service
*
* @param <https://github.com/param> ServiceLocatorInterface
$serviceLocator
*
* @return <https://github.com/return> mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$realServiceLocator = $serviceLocator->getServiceLocator();
$postService = $realServiceLocator->get('Blog\Service\
PostServiceInterface');
return new ListController($postService);
}
}my PostService:<?php
// Filename: /module/Blog/src/Blog/Service/PostService.php
namespace Blog\Service;
use Blog\Mapper\PostMapperInterface;
class PostService implements PostServiceInterface
{
protected $postMapper;
public function findAllPosts()
{
// TODO: Implement findAllPosts() method.
return $this->postMapper->findAll();
}
/**
* ***@***.***}
*/
public function findPost($id)
{
// TODO: Implement findPost() method.
return $this->postMapper->find($id);
}
public function __construct(PostMapperInterface $postMapper)
{
$this->postMapper = $postMapper;
}
}my PostServiceMapper:<?php
// Filename: /module/Blog/src/Blog/Factory/PostServiceFactory.php
namespace Blog\Factory;
use Blog\Service\PostService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class PostServiceFactory implements FactoryInterface
{
/**
* Create service
*
* @param <https://github.com/param> ServiceLocatorInterface
$serviceLocator
* @return <https://github.com/return> mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new PostService(
$serviceLocator->get('Blog\Mapper\PostMapperInterface')
);
}
}my ZendDbSqlMapper:<?php
// Filename: /module/Blog/src/Blog/Mapper/ZendDbSqlMapper.php
namespace Blog\Mapper;
use Blog\Model\PostInterface;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\Sql\Sql;
class ZendDbSqlMapper implements PostMapperInterface
{
/**
* @var <https://github.com/var> \Zend\Db\Adapter\AdapterInterface
*/
protected $dbAdapter;
/**
* @param AdapterInterface $dbAdapter
*/
public function __construct(AdapterInterface $dbAdapter)
{
$this->dbAdapter = $dbAdapter;
}
/**
* @param int|string $id
*
* @return PostInterface
* @throws \InvalidArgumentException
*/
public function find($id)
{
}
/**
* @return array|PostInterface[]
*/
public function findAll()
{
$sql = new Sql($this->dbAdapter);
$select = $sql->select('posts');
$stmt = $sql->prepareStatementForSqlObject($select);
$result = $stmt->execute();
return $result;
}
}`
Any help apreciated, i been stuck for ages now D:
thanks for the atention
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3125>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFvo_HoLvC2xn9xAnIip3dBqBy0zRP5Dks5rjEb3gaJpZM4MUeR6>
.
|
sorry, first post.. xd |
no problem, can you please close this. Thanks |
why? what am i doin wrong? |
@monteiro07 You are posting your issue on the issue tracker of crouton. Looking at your question this has nothing to do with crouton, you probably want another git here on github. Like somewhere here https://github.com/zendframework/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, i have been following step by step the beginners guide of Zend Framework 2 on their website (https://framework.zend.com/manual/2.4/en/in-depth-guide/preparing-db-backend.html) and i encountered the following error:
An exception was raised while creating "Blog\Controller\List"; no instance returned
stack trace:
#0 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(284): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Array, 'blogcontrollerl...', 'Blog\Controller...')
#1 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(242): Zend\ServiceManager\AbstractPluginManager->createServiceViaCallback(Array, 'blogcontrollerl...', 'Blog\Controller...')
#2 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(638): Zend\ServiceManager\AbstractPluginManager->createFromFactory('blogcontrollerl...', 'Blog\Controller...')
#3 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(598): Zend\ServiceManager\ServiceManager->doCreate('Blog\Controller...', 'blogcontrollerl...')
#4 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(530): Zend\ServiceManager\ServiceManager->create(Array)
#5 C:\wamp64\www\zf2\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(116): Zend\ServiceManager\ServiceManager->get('Blog\Controller...', false)
#6 C:\wamp64\www\zf2\vendor\zendframework\zend-mvc\src\Controller\ControllerManager.php(137): Zend\ServiceManager\AbstractPluginManager->get('Blog\Controller...', Array, false)
#7 C:\wamp64\www\zf2\vendor\zendframework\zend-mvc\src\DispatchListener.php(76): Zend\Mvc\Controller\ControllerManager->get('Blog\Controller...')
#8 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 C:\wamp64\www\zf2\vendor\zendframework\zend-eventmanager\src\EventManager.php(444): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#10 C:\wamp64\www\zf2\vendor\zendframework\zend-eventmanager\src\EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 C:\wamp64\www\zf2\vendor\zendframework\zend-mvc\src\Application.php(314): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 C:\wamp64\www\zf2\public\index.php(21): Zend\Mvc\Application->run()
#13 {main}
Any help apreciated, i been stuck for ages now D:
thanks for the atention
The text was updated successfully, but these errors were encountered: