2017-10-09 13 views
-1

Zendフレームワーク3では、新しいコントローラ "ArticleController"を既存のモジュールCityに追加しようとしましたが失敗しました。私はスクリーンショット、私のフォルダ構造とmodule.config.phpを投稿します。問題が何であるか説明できますか?アクセスするときhttp://0.0.0.0:7000/city既存のモジュールに新しいコントローラをzf3に追加

にアクセスする際ちなみに、それが働いたhttp://0.0.0.0:7000/article enter image description here enter image description here

次に、モジュール\街\ 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', 
     ], 
    ], 
]; 

答えて

2

エラーメッセージが明確です。アプリケーションはあなたのコントローラーについて何も知らない。あなたのモジュールの設定は "コントローラ"キーの下にあるコントローラに関する情報を持っていなければなりません。チェックアウトzend documentationを実行すると、設定ファイルに "controllers"キーが表示されます。

+0

ご回答いただきありがとうございます。私は "controller"をmodule.config.phpに追加しようとしましたが、失敗しました。それから、私は解決策を見つけました。 City/src/Module.phpのキー "factory"にアーティクルコントローラの値を追加します。 zend frameworkチュートリアルを終えた後、私は新しいコントローラを追加しようとしました。チュートリアルは "工場"を適用したので成功しませんでした。 https://docs.zendframework.com/tutorials/getting-started/database-and-models/非常に残念ですが、Mehmet。 – hikozuma

+0

あなたの "コントローラ"設定は次のようになります ["controllers" => ["Factory" => "MyControllerFactory"]]] これは "コントローラ"の設定方法です。コントローラに依存性注入がない場合、工場は必要ありません。したがって、あなたは "invokables"キーの下にそれを登録します。 ["controllers" => ["invokables" => ["MyController"]]] –

関連する問題