0
votes

As per subject, how to solve the initilizer problem for the Zend/Http?

In my controller:

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
        ]);
    }  

in 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',
];

error:


Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (Zend\Http) could not be initialized.' in /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php:203 Stack trace:

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(Object(Zend\ModuleManager\ModuleEvent))

3 /var/www/html/zf3/blog/vendor/zendframework/zend-eventmanager/src/EventManager.php(143):

Zend\EventManager\EventManager->triggerListeners(Object(Zend\ModuleManager\ModuleEvent))

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

in /var/www/html/zf3/blog/vendor/zendframework/zend-modulemanager/src/ModuleManager.php on line 203

Did I miss out anything?

1
zend\http is not a moduleXerkus

1 Answers

2
votes

Try to download package via composer with this command:

composer require zendframework/zend-http