Zendframework 3 - 无法初始化Zend / http

时间:2016-10-05 13:22:09

标签: php zend-framework zend-http-client zf3

根据主题,如何解决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(对象(的Zend \ ModuleManager会\ ModuleEvent))

     

1 /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(97):

     

的Zend \ ModuleManager会\ ModuleManager->加载模块( '的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):

     

在    /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php 的   在线 203

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

尝试使用此命令通过composer下载包:

composer require zendframework/zend-http