Php ';名为“的插件”;示例\段“;在插件管理器Zend\Router\RoutePluginManager中找不到
我目前正在学习Zend 3教程。唯一的区别是我使用的是示例表/类而不是相册。除每次尝试访问dev服务器时出现以下错误外,所有内容都符合规范要求: 致命错误:未捕获异常 带有消息的“Zend\ServiceManager\Exception\ServiceNotFoundException” '在插件中找不到名为“Example\Segment”的插件 manager Zend\Router\RoutePluginManager'位于 C:\Websites\ZEND2\vendor\zendframework\zend servicemanager\src\AbstractPluginManager.php:133 堆栈跟踪:#0 C:\Websites\ZEND2\vendor\zendframework\zend router\src\SimpleRouteStack.php(280): Zend\ServiceManager\AbstractPluginManager->get('Example\Segment', 数组)#1 C:\Websites\ZEND2\vendor\zendframework\zend router\src\Http\TreeRouteStack.php(201): Zend\Router\SimpleRouteStack->routeFromArray(阵列)#2 C:\Websites\ZEND2\vendor\zendframework\zend router\src\Http\TreeRouteStack.php(151): Zend\Router\Http\TreeRouteStack->routeFromArray(数组)#3 C:\Websites\ZEND2\vendor\zendframework\zend router\src\SimpleRouteStack.php(142): Zend\Router\Http\TreeRouteStack->addRoute('example',Array)#4 C:\Websites\ZEND2\vendor\zendframework\zend router\src\SimpleRouteStack.php(86): Zend\Router\SimpleRouteStack->addRoutes(数组)中的 C:\Websites\ZEND2\vendor\zendframework\zend servicemanager\src\AbstractPluginManager.php 在线133 ExampleController.phpPhp ';名为“的插件”;示例\段“;在插件管理器Zend\Router\RoutePluginManager中找不到,php,zend-framework,Php,Zend Framework,我目前正在学习Zend 3教程。唯一的区别是我使用的是示例表/类而不是相册。除每次尝试访问dev服务器时出现以下错误外,所有内容都符合规范要求: 致命错误:未捕获异常 带有消息的“Zend\ServiceManager\Exception\ServiceNotFoundException” '在插件中找不到名为“Example\Segment”的插件 manager Zend\Router\RoutePluginManager'位于 C:\Websites\ZEND2\vendor\zendfr
namespace Example\Controller;
use Example\Model\ExampleTable;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class ExampleController extends AbstractActionController
{
private $table;
public function indexAction()
{
return new ViewModel([
'examples' => $this->table->fetchAll(),
]);
}
public function addAction()
{
}
public function editAction()
{
}
public function deleteAction()
{
}
public function __construct(ExampleTable $table)
{
$this->table = $table;
}
}
ExampleTable.php
<?php
namespace Example\Model;
use RuntimeException;
use Zend\Db\TableGateway\TableGatewayInterface;
class ExampleTable
{
private $tableGateway;
public function __construct(TableGatewayInterface $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchAll()
{
return $this->tableGateway->select();
}
public function getExample($id)
{
$id = (int) $id;
$rowset = $this->tableGateway->select(['id' => $id]);
$row = $rowset->current();
if (! $row) {
throw new RuntimeException(sprintf(
'Could not find row with identifier %d',
$id
));
}
return $row;
}
public function saveExample(Example $example)
{
$data = [
'name' => $example->name,
'description' => $example->description,
'web_url' => $example->web_url,
];
$id = (int) $example->id;
if ($id === 0) {
$this->tableGateway->insert($data);
return;
}
if (! $this->getExample($id)) {
throw new RuntimeException(sprintf(
'Cannot update example with identifier %d; does not exist',
$id
));
}
$this->tableGateway->update($data, ['id' => $id]);
}
public function deleteExample($id)
{
$this->tableGateway->delete(['id' => (int) $id]);
}
}
modules.config.php
<?php
namespace Example;
return [
// The following section is new and should be added to your file:
'router' => [
'routes' => [
'example' => [
'type' => Segment::class,
'options' => [
'route' => '/example[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ExampleController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'example' => __DIR__ . '/../view',
],
],
];
<?php
/**
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* List of enabled modules for this application.
*
* This should be an array of module namespaces used in the application.
*/
return [
'Zend\Form',
'Zend\Db',
'Zend\Router',
'Zend\Validator',
'Application',
'Example',
];
您的module.config.php
文件需要一个:
use Zend\Router\Http\Segment;
在顶部附近声明以创建稍后在文件中使用的段
别名。目前,由于该类不存在,PHP正在您声明的名称空间中查找该类(因此Example\Segment
),该类不存在。请仅包含修复该问题所需的代码。请参阅module.config.php
write'segment'
中的堆栈溢出指导原则,以取代segment::class
Nice、worked和removes错误!当你试着迈出第一步时,像这样的洞出现在你的脚下,这真是令人沮丧。谢谢你,蒂姆
<?php
/**
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* List of enabled modules for this application.
*
* This should be an array of module namespaces used in the application.
*/
return [
'Zend\Form',
'Zend\Db',
'Zend\Router',
'Zend\Validator',
'Application',
'Example',
];
use Zend\Router\Http\Segment;