根据主题,如何解决 Zend/Http 的初始化程序问题?
在我的控制器中:
use Zend\Http\Client;
class AuthController extends AbstractActionController
{
/**
* Entity manager.
* @var Doctrine\ORM\EntityManager
*/
public $entityManager;
/**
* Post manager.
* @var Application\Service\PostManager
*/
private $postManager;
private $sessionManager;
/**
* Constructor is used for injecting dependencies into the controller.
*/
public function __construct($entityManager, $postManager, $sessionManager)
{
$this->entityManager = $entityManager;
$this->postManager = $postManager;
$this->sessionManager = $sessionManager;
}
//LoginForm
public function indexAction()
{
// Create the form.
$form = new LoginForm();
if (!empty($this->sessionManager->username)) {
return $this->redirect()->toRoute('plan', ['controller'=>'index', 'action'=>'index']);
}
else {
$this->layout('layout/layout_login');
// Check whether this post is a POST request.
$this->sessionManager->username = '';
if ($this->getRequest()->isPost()) {
// Get POST data.
$data = $this->params()->fromPost();
// Fill form with data.
$form->setData($data);
if ($form->isValid())
{
// Get validated form data.
$data = $form->getData();
$this->sessionManager->username = $data['email'];
$postUrl = "http://example.com/jwt/auth/login/";
$config = array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
);
$client = new Zend\Http\Client($postUrl, $config);
$client = new Zend\Http\Client;
$client->getHeaders()->addHeaders([
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
]);
$client->setUri($postUrl);
$client->setMethod('POST'); //uncomment this if the POST is used
$client->getPost()->set('username', $data['email']);
$client->getPost()->set('password', $data['password']);
$client = new Client;
//$client->setAdapter("Zend\Http\Client\Adapter\Curl");
$response = $client->dispatch($client);
// Redirect the user to "index" page.
return $this->redirect()->toRoute('application', ['controller'=>'index', 'action'=>'playground']);
}
}
}
// Render the view template.
return new ViewModel([
'form' => $form
]);
}
在 config\modules.config.php 中:
return [
'DoctrineModule',
'DoctrineORMModule',
'Zend\Http',
'Zend\Cache',
'Zend\Paginator',
'Zend\I18n',
'Zend\InputFilter',
'Zend\Filter',
'Zend\Hydrator',
'Zend\Session',
'Zend\Mvc\Plugin\Prg',
'Zend\Mvc\Plugin\Identity',
'Zend\Mvc\Plugin\FlashMessenger',
'Zend\Mvc\Plugin\FilePrg',
'Zend\Form',
'Zend\Router',
'Zend\Validator',
'Zend\Validator',
'Application',
];
错误:
致命错误:未捕获的异常 'Zend\ModuleManager\Exception\RuntimeException' 带有消息 'Module (Zend\Http) 无法初始化。' 在 /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php:203 堆栈跟踪:0 /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(175):
Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
1 /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(97):
Zend\ModuleManager\ModuleManager->loadModule('Zend\Http')
2 /var/www/html/zf3/blog/vendor/zendframework/zend-eventmanager/src/EventManager.php(271):
Zend\ModuleManager\ModuleManager->onLoadModules(对象(Zend\ModuleManager\ModuleEvent))
3 /var/www/html/zf3/blog/vendor/zendframework/zend-eventmanager/src/EventManager.php(143):
Zend\EventManager\EventManager->triggerListeners(对象(Zend\ModuleManager\ModuleEvent))
4 /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(120):
在 第203 行的/var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php
我错过了什么吗?