2016-08-31 3 views
1

に見つかりませんでした私はframework.zend.comZend Frameworkの2 - 名前でプラグイン「getServiceLocatorは、」プラグインマネージャ

からこのtutorialに従い、このエラーを得てきました:

Zend\ServiceManager\Exception\ServiceNotFoundException 

A plugin by the name "getServiceLocator" was not found in the plugin manager 
Zend\Mvc\Controller\PluginManager 


#0 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Controller\PluginManager.php(98): Zend\ServiceManager\AbstractPluginManager->get('getServiceLocat...', NULL) 
#1 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Controller\AbstractController.php(258): Zend\Mvc\Controller\PluginManager->get('getServiceLocat...', NULL) 
#2 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Controller\AbstractController.php(273): Zend\Mvc\Controller\AbstractController->plugin('getServiceLocat...') 
#3 C:\xampp\htdocs\skeleton-application\module\Album\src\Album\Controller\AlbumController.php(33): Zend\Mvc\Controller\AbstractController->__call('getServiceLocat...', Array) 
#4 C:\xampp\htdocs\skeleton-application\module\Album\src\Album\Controller\AlbumController.php(33): Album\Controller\AlbumController->getServiceLocator() 
#5 C:\xampp\htdocs\skeleton-application\module\Album\src\Album\Controller\AlbumController.php(14): Album\Controller\AlbumController->getAlbumTable() 
#6 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Controller\AbstractActionController.php(78): Album\Controller\AlbumController->indexAction() 
#7 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-eventmanager\src\EventManager.php(271): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent)) 
#8 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-eventmanager\src\EventManager.php(151): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure)) 
#9 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Controller\AbstractController.php(105): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent)) 
#10 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\DispatchListener.php(119): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response)) 
#11 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-eventmanager\src\EventManager.php(271): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent)) 
#12 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-eventmanager\src\EventManager.php(151): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure)) 
#13 C:\xampp\htdocs\skeleton-application\vendor\zendframework\zend-mvc\src\Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent)) 
#14 C:\xampp\htdocs\skeleton-application\public\index.php(40): Zend\Mvc\Application->run() 
#15 {main} 

ここでエラーが現れ私のAlbumControllerです:

<?php 
namespace Album\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 

class AlbumController extends AbstractActionController 
{ 
    protected $albumTable; 

    public function indexAction() 
    { 
     return new ViewModel(array(
      'albums' => $this->getAlbumTable()->fetchAll(), 
     )); 
    } 

    public function addAction() 
    { 
    } 

    public function editAction() 
    { 
    } 

    public function deleteAction() 
    { 
    } 

    public function getAlbumTable() 
    { 
     if (!$this->albumTable) { 
      $sm = $this->getServiceLocator(); 
      $this->albumTable = $sm->get('Album\Model\AlbumTable'); 
     } 
     return $this->albumTable; 
    } 
} 

これは私のAlbumTableです:

<?php 
namespace Album\Model; 

use Zend\Db\TableGateway\TableGateway; 

class AlbumTable 
{ 
    protected $tableGateway; 

    public function __construct(TableGateway $tableGateway) 
    { 
     $this->tableGateway = $tableGateway; 
    } 

    public function fetchAll() 
    { 
     $resultSet = $this->tableGateway->select(); 
     return $resultSet; 
    } 

    public function getAlbum($id) 
    { 
     $id = (int) $id; 
     $rowset = $this->tableGateway->select(array('id' => $id)); 
     $row = $rowset->current(); 
     if (!$row) { 
      throw new \Exception("Could not find row $id"); 
     } 
     return $row; 
    } 

    public function saveAlbum(Album $album) 
    { 
     $data = array(
      'artist' => $album->artist, 
      'title' => $album->title, 
     ); 

     $id = (int) $album->id; 
     if ($id == 0) { 
      $this->tableGateway->insert($data); 
     } else { 
      if ($this->getAlbum($id)) { 
       $this->tableGateway->update($data, array('id' => $id)); 
      } else { 
       throw new \Exception('Album id does not exist'); 
      } 
     } 
    } 

    public function deleteAlbum($id) 
    { 
     $this->tableGateway->delete(array('id' => (int) $id)); 
    } 
} 

プラグインのスクリプトファイルが壊れているかどうか分かりません。バージョン3.0.2devを使用しているため、バージョン違いです。2.4となっています。

答えて

1

getServiceLocatorは2.5バージョンから廃止されました.3 * では削除されましたので、コントローラで使用しないでください。

依存関係を注入する場合。 here it has been explained

あなたが使用しているリソースは2. *バージョンに属しています。

以下、zf3に関連するリソースはほとんど紹介していません。あなたは一見を持つことができます。 zf3 official referencezf3 tutorials

https://github.com/olegkrivtsov/using-zf3-book-samples

関連する問題