- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我目前正在学习 Zend 3 教程。唯一的区别是我使用的是示例表/类而不是相册。一切似乎都符合规范,除了我每次尝试访问开发服务器时都会收到以下错误:
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'A plugin by the name "Example\Segment" was not found in the plugin manager Zend\Router\RoutePluginManager' in C:\Websites\ZEND2\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php:133 Stack trace: #0 C:\Websites\ZEND2\vendor\zendframework\zend-router\src\SimpleRouteStack.php(280): Zend\ServiceManager\AbstractPluginManager->get('Example\Segment', Array) #1 C:\Websites\ZEND2\vendor\zendframework\zend-router\src\Http\TreeRouteStack.php(201): Zend\Router\SimpleRouteStack->routeFromArray(Array) #2 C:\Websites\ZEND2\vendor\zendframework\zend-router\src\Http\TreeRouteStack.php(151): Zend\Router\Http\TreeRouteStack->routeFromArray(Array) #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(Array) in C:\Websites\ZEND2\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php on line 133
ExampleController.php
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]);
}
}
模块.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
<?php
namespace Example;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '\config\module.config.php';
}
// Add this method:
public function getServiceConfig()
{
return [
'factories' => [
Model\ExampleTable::class => function($container) {
$tableGateway = $container->get(Model\ExampleTableGateway::class);
return new Model\ExampleTable($tableGateway);
},
Model\ExampleTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Example());
return new TableGateway('example', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\ExampleController::class => function($container) {
return new Controller\ExampleController(
$container->get(Model\ExampleTable::class)
);
},
],
];
}
}
例子.php
namespace Example\Model;
class Example
{
public $id;
public $name;
public $description;
public $web_url
public function exchangeArray(array $data)
{
$this->id = !empty($data['id']) ? $data['id'] : null;
$this->name = !empty($data['name']) ? $data['name'] : null;
$this->description = !empty($data['description']) ? $data['description'] : null;
$this->web_url = !empty($data['web_url']) ? $data['web_url'] : null;
}
}
modules.config.php
<?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;
靠近顶部的声明,用于创建稍后在文件中使用的 Segment
别名。目前,因为它不存在,PHP 正在您声明的命名空间(所以 Example\Segment
)中寻找那个不存在的类。
关于php - '在插件管理器 Zend\Router\RoutePluginManager 中找不到名为 "Example\Segment"的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38470511/
我正在使用 Mechanize 配置 ssl , 根据 document我需要设置 agent.cert = 'example.cer' agent.key='example.cer' 但是我怎样才能
我有一个表格,允许人们将士兵添加到列表中,该列表可以很好地传输到 mysql。如果我在没有变量的情况下这样做甚至很好,但是一旦我尝试添加一个如下所示。 // Get Variable from Loc
使用 .htaccess 重写,我想要: http://example.com 重定向到:http://www.example.comhttps://www.example.com 重定向到:http
我想将所有流量重定向到 https://www.sitename.com 例子 http://sitename.com --> https://www.sitename.com http://www.
我只有 example.com 的 SSL 证书,并且想同时重定向 http://example.com和 http://*.example.com 到 https://example.com使用 n
我有服务器 A,它托管我们在 www.example.com 上的主要站点;我们有一个涵盖 *.example.com 的 SSL 证书。 在我们网站的安全部分,我们希望向我们编写并托管在单独机器/I
我正在努力平衡多行上的一些文本,并且我正在添加手动换行符以将文本均匀地分割在各行上。为了弄清楚这一点,我需要查看在哪里添加“\n”来测试我的代码,但我发现的唯一方法是将其全部打印为字符: ["T",
我在我们的域中安装了 Apache 和 Tomcat 服务器,因为我有超过 25 个服务,一些服务由 Apache 处理,一些服务由 Tomcat 处理。 tomcat 服务显示 http://exa
编辑:问题终于解决了。详细信息可以在此消息末尾的疑难解答部分中找到。 我在这里保留了详细的步骤,以防可能对某人有所帮助。 设置OpenLDAP I-创建服务器 该文档通常已经过时,并且您会找到多种实现
这个问题在这里已经有了答案: offsetting an html anchor to adjust for fixed header [duplicate] (28 个答案) 关闭 8 年前。
目前谷歌将我的网站链接显示为... example.com/ ...但是,我希望它显示为... example.com 我确实有以下元数据 ...下面是我的 htaccess 文件... Index
我使用 Microsoft Visual Studio 2012。当我将代码示例放入 C# 类/方法的 XML 注释中时,我想知道:引用我的程序集的用户将如何看到该代码示例? 我试图引用我自己的程序集
我对正则表达式还很陌生,无法真正弄清楚它是如何工作的。我试过这个: function change_email($email){ return preg_match('/^[\w]$/', $e
我正在使用 Hibernate 版本 4.3.5.Final。这里的问题是 Hibernate 找到 Foo 类型的实体,其中属性 address 的大小写不同(例如“BLAFOO”)。但是,在我的示
我为环境特定变量(如用户名和密码)设置了一个环境 YAML 文件。要在我的应用程序中使用这些变量,我需要使用 APP_CONFIG['username']而不是 APP_CONFIG[:usernam
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
这个问题在这里已经有了答案: Does Python have a string 'contains' substring method? (10 个答案) 关闭 8 年前。 我想检查发件人 hea
我已经在 https://arieldemian.it 上配置了 SSL/TLS但似乎https://www.arieldemian.it不安全。这是为什么?我需要注册他们两个吗?我正在使用 http
当我使用 ProGuard 时,com.example.** 和 com.example.**{*;} 之间的区别是什么?例如,每种情况会发生什么情况? -keep class com.examp
我的主页的内容是根据使用 slug“home”对数据库的查询提取的。例如,如果我在地址栏中输入 example.com/home,它会根据看到的“/home”查询数据库并提取正确的内容(使用变量“$p
我是一名优秀的程序员,十分优秀!