大家好,我是 Zend 的新手,被要求使用 Z2 进行开发。我正在尝试通过控制器插件添加可重用的功能,但我没有成功进行单元测试。它在常规应用程序中运行良好。
// Application\Controller\Plugin\HelloWorld.php
namespace Application\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Http\Client;
use Zend\Http\Request;
class HelloWorld extends AbstractPlugin
{
public function helloWorld()
{
return "HELLO WORLD";
}
}
// Application\Controller\IndexController.php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
echo $this->helloworld()->helloWorld();
}
}
//Application\config\module.config.php
...
'controller_plugins' => array(
'invokables' => array(
'helloworld' => 'Application\Controller\Plugin\HelloWorld',
),
),
...
我得到的错误是:
Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for helloworld