-1
Zendフレームワーク3では、新しいコントローラ "ArticleController"を既存のモジュールCityに追加しようとしましたが失敗しました。私はスクリーンショット、私のフォルダ構造とmodule.config.phpを投稿します。問題が何であるか説明できますか?アクセスするときhttp://0.0.0.0:7000/city既存のモジュールに新しいコントローラをzf3に追加
にアクセスする際ちなみに、それが働いたhttp://0.0.0.0:7000/article
次に、モジュール\街\ CONFIG \ module.config.phpコードは次のとおりです。
<?php
namespace City;
use Zend\Router\Http\Segment;
return [
'router' => [
'routes' => [
'city' => [
'type' => Segment::class,
'options' => [
'route' => '/city[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\CityController::class,
'action' => 'index',
],
],
],
'article' => [
'type' => Segment::class,
'options' => [
'route' => '/article[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\ArticleController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'city' => __DIR__ . '/../view',
],
],
];
ご回答いただきありがとうございます。私は "controller"をmodule.config.phpに追加しようとしましたが、失敗しました。それから、私は解決策を見つけました。 City/src/Module.phpのキー "factory"にアーティクルコントローラの値を追加します。 zend frameworkチュートリアルを終えた後、私は新しいコントローラを追加しようとしました。チュートリアルは "工場"を適用したので成功しませんでした。 https://docs.zendframework.com/tutorials/getting-started/database-and-models/非常に残念ですが、Mehmet。 – hikozuma
あなたの "コントローラ"設定は次のようになります ["controllers" => ["Factory" => "MyControllerFactory"]]] これは "コントローラ"の設定方法です。コントローラに依存性注入がない場合、工場は必要ありません。したがって、あなたは "invokables"キーの下にそれを登録します。 ["controllers" => ["invokables" => ["MyController"]]] –