\ module \ Album \ src \ Album \ FactoryフォルダにAlbumControllerFactory.phpを作成しました。controlleralbumcontroller(別名:Controller AlbumController)を作成しようとしたときに、このインスタンスタイプに対して無効なファクトリが登録されました
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Album\Model\Album;
use Album\Form\AlbumForm;
class AlbumController extends AbstractActionController
{
protected $_albumTable;
public function __construct(AlbumTable $albumTable)
{
$this->_albumTable = $albumTable;
}
public function indexAction()
{
return new ViewModel(array(
'albums' => $this->getAlbumTable()->fetchAll(),
));
}
}
:use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Album\Controller\AlbumController;
class AlbumControllerFactory implements FactoryInterface
{
/**
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return AlbumController
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$class = $requestedName ? $requestedName : AlbumController::class;
$albumTable = $container->get('Album\Model\AlbumTable'); // get service from service manager
$controller = new $class($albumTable);
return $controller;
}
/**
* Provided for backwards compatibility; proxies to __invoke().
*
* @param ContainerInterface|ServiceLocatorInterface $container
* @return AlbumController
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, AlbumController::class);
}
}
上記そして、私のコントローラで私は私の工場を取得するコードを以下したエラーを示します
そして、次のようなとして私module.config.phpに私は、コントローラを設定している:
return array(
'controllers' => array(
'factories' => array(
Controller\AlbumController::class => Factory\Controller\AlbumControllerFactory::class,
),
)を、
ので、私はそれとして私のモジュールの作業罰金を作るために、順序、この問題を解決するにはどうすればよいですファクトリを作成する前にうまくいきましたが、廃止予定のメッセージが表示されていました。私が何をしたのか、そしてこれを解決する方法を教えてください。
メイン
Factory
ディレクトリ内のすべてのあなたの工場を維持しますが、彼らのために正しい名前空間を設定してくださいとmodule.config.php
ファイルにすることができますが、 '持っていますか'module.config.php'ファイルの先頭にあるAlbum \ Controller'と' Album \ Factory'を使用しますか? – SzymonMまだ同じエラー:@SzymonM – Shoaib
'AlbumControllerFactory'クラスの名前空間とは何ですか? – SzymonM