Please, help me to solve the following problem in ZendFramework.
I'm new in ZF and PHP7. For a few days I havent been able to use Doctrine EntityManager in controller.
I have:
My Controller
namespace Sonun\Controller;
use Zend\Mvc\Controller\AbstractActionController,
Doctrine\ORM\EntityManager;
class IndexController extends AbstractActionController
{
protected $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
Factory
namespace Sonun\Controller;
use Sonun\Controller\IndexController,
Zend\ServiceManager\FactoryInterface,
Zend\ServiceManager\ServiceLocatorInterface;
class IndexControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $sm)
{
$entityManager = $sm->get("Doctrine\ORM\EntityManager");
return new IndexController($entityManager);
}
}
module.config.php
return [
"controllers" => [
"invokables" => [
"Sonun\Controller\IndexController" => "Sonun\Controller\IndexController"
]
],
"router" => [
"routes" => [
"sonun" => [
"type" => "segment",
"options" => [
"route" => "/sonun/[:action/][:id/]",
"constraints" => [
"action" => "[a-zA-Z0-9_-]*",
"id" => "[0-9]*"
],
"defaults" => [
"controller" => "Sonun\Controller\IndexController",
"action" => "index"
]
]
]
]
],
"view_manager" => [
"template_path_stack" => [
__DIR__."/../view"
]
],
"service_manager" => [
"factories" => [
"Sonun\Controller\IndexController" => "Sonun\Controller\IndexControllerFactory"
]
]
]
Error
Fatal error: Uncaught TypeError: Argument 1 passed to ZendDeveloperTools\Exception\SerializableException::__construct() must be an instance of Exception, instance of TypeError given, called in C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Collector\ExceptionCollector.php on line 45 and defined in C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Exception\SerializableException.php:26 Stack trace: #0 C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Collector\ExceptionCollector.php(45): ZendDeveloperTools\Exception\SerializableException->__construct(Object(TypeError)) #1 C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Profiler.php(210): ZendDeveloperTools\Collector\ExceptionCollector->collect(Object(Zend\Mvc\MvcEvent)) #2 C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Listener\ProfilerListener.php(93): ZendDeveloperTools\Profiler->collect(Object(Zend\Mvc\MvcEvent)) #3 C:\xampp\htdocs\sonun\vendor\zendframework\zend-eventmanag in C:\xampp\htdocs\sonun\vendor\zendframework\zend-developer-tools\src\Exception\SerializableException.php on line 26