簡體   English   中英

ZendFatal錯誤:找不到類'Zend \\ Ldap \\ Ldap'

[英]ZendFatal error: Class 'Zend\Ldap\Ldap' not found

因此,我正在嘗試按照中的文檔進行Ldap身份驗證

https://zf2.readthedocs.org/en/latest/user-guide/skeleton-application.html

我只是將“相冊”模塊替換為“身份驗證”模塊,並使用示例代碼進行Ldap驗證

https://zf2.readthedocs.org/en/latest/modules/zend.authentication.adapter.ldap.html

但是我在提交帶有登錄數據的表單時Zend找不到Ldap類時出現了此錯誤。

致命錯誤:在第139行的C:\\ wamp \\ www \\ sade \\ vendor \\ zendframework \\ zend-authentication \\ src \\ Adapter \\ Ldap.php中找不到類'Zend \\ Ldap \\ Ldap'

我正在使用composer,對於zend框架和用於模塊的atuoloader,我已經遇到了與找不到一個類有關的錯誤,但我自己的類,而不是諸如Ldap之類的Zend類。

謝謝。

這是文件和文件夾的結構

/module
     /Auth
         /config
            module.config.php
         /src
             /Auth
                 /Controller
                    AuthController.php
                 /Form
                    AuthForm.php
                 /Model
                 Auth.php
         /view
             /auth
                 /auth
                    index.php
        Module.php

以及模塊的主要代碼:

module.config.php

 return array(
 'controllers' => array(
     'invokables' => array(
         'Auth\Controller\Auth' => 'Auth\Controller\AuthController',
     ),
 ),
'router' => array(
     'routes' => array(
         'auth' => array(
             'type'    => 'segment',
             'options' => array(
                 'route'    => '/auth[/:action][/:id]',
                 'constraints' => array(
                     'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                     'id'     => '[0-9]+',
                 ),
                 'defaults' => array(
                     'controller' => 'Auth\Controller\Auth',
                     'action'     => 'index',
                 ),
             ),
         ),
     ),
 ),

 'view_manager' => array(
     'template_path_stack' => array(
         'auth' => __DIR__ . '/../view',
     ),
 ),
);

AuthController.php

//AuthController.php
namespace Auth\Controller;

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

use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Adapter\Ldap as AuthAdapter;
use Zend\Config\Reader\Ini as ConfigReader;
use Zend\Config\Config;
use Zend\Log\Logger;
use Zend\Log\Writer\Stream as LogWriter;
use Zend\Log\Filter\Priority as LogFilter;

use Auth\Model\Auth;  
use Auth\Form\AuthForm; 

 class AuthController extends AbstractActionController
 {
     public function indexAction()
     {
     $form = new AuthForm();
     $form->get('submit')->setValue('index');
     $request = $this->getRequest();
     if ($request->isPost()) {
        $Auth = new Auth();
        $Auth->username = $this->getRequest()->getPost('username');
        $Auth->password = $this->getRequest()->getPost('password');


        $AuthenticationService = new AuthenticationService();

        $configReader = new ConfigReader();
        $configData = $configReader->fromFile('config/ldap-config.ini');
        $config = new Config($configData, true);
        $log_path = $config->production->ldap->log_path;
        //die($log_path)."--";
        $options = $config->production->ldap->toArray();
        unset($options['log_path']);

        $adapter = new AuthAdapter($options,
                                   $Auth->username,
                                   $Auth->password);

        $form->setInputFilter($Auth->getInputFilter());
        $form->setData($request->getPost());
        $result = $AuthenticationService->authenticate($adapter);

            if ($log_path) {
                    $messages = $result->getMessages();

                    $logger = new Logger;
                    $writer = new LogWriter($log_path);

                    $logger->addWriter($writer);

                    $filter = new LogFilter(Logger::DEBUG);
                    $writer->addFilter($filter);

                    foreach ($messages as $i => $message) {
                        if ($i-- > 1) { // $messages[2] and up are log messages
                            $message = str_replace("\n", "\n  ", $message);
                            $logger->debug("Ldap: $i: $message");
                        }
                    }
                }                 
            //return $this->redirect()->toRoute('login');
     }
     return array('form' => $form);

 }

 public function LoginAction()
 {
 }
 public function LogoutAction()

 {
 }
 }

AuthForm.php

//AuthForm.php

namespace Auth\Form;

 use Zend\Form\Form;

 class AuthForm extends Form
 {
     public function __construct($name = null)
     {
     // we want to ignore the name passed
     parent::__construct('auth');

     $this->add(array(
         'name' => 'username',
         'type' => 'Text',
         'options' => array(
             'label' => 'Nombre de usuario',
         ),
     ));
     $this->add(array(
         'name' => 'password',
         'type' => 'Password',
         'options' => array(
             'label' => 'Contraseña',
         ),
     ));
     $this->add(array(
         'name' => 'submit',
         'type' => 'Submit',
         'attributes' => array(
             'value' => 'Iniciar sesión',
             'id' => 'submitbutton',
         ),
     ));
 }
 }

Auth.php (位於“模型”文件夾中,用於以后可能實現的過濾器)

namespace Auth\Model;

 // Add these import statements
 use Zend\InputFilter\InputFilter;
 use Zend\InputFilter\InputFilterAwareInterface;
 use Zend\InputFilter\InputFilterInterface;

 class Auth implements InputFilterAwareInterface
 {
 public $username;
 public $password;
 protected $inputFilter;                       // <-- Add this variable

 public function exchangeArray($data)
 {
     $this->username = (isset($data['username'])) ? $data['username'] : null;
     $this->password  = (isset($data['password']))  ? $data['password']  : null;
 }

 // Add content to these methods:
 public function setInputFilter(InputFilterInterface $inputFilter)
 {
     throw new \Exception("Not used");
 }

 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();

         $inputFilter->add(array(
             'name'     => 'username',
             'required' => true,
             'filters'  => array(
                 array('name' => 'StripTags'),
                 array('name' => 'StringTrim'),
             ),
             'validators' => array(
                 array(
                     'name'    => 'StringLength',
                     'options' => array(
                         'encoding' => 'UTF-8',
                         'min'      => 1,
                         'max'      => 100,
                     ),
                 ),
             ),
         ));

         $inputFilter->add(array(
             'name'     => 'password',
             'required' => true,
             'filters'  => array(
                 array('name' => 'StripTags'),
                 array('name' => 'StringTrim'),
             ),
             'validators' => array(
                 array(
                     'name'    => 'StringLength',
                     'options' => array(
                         'encoding' => 'UTF-8',
                         'min'      => 1,
                         'max'      => 100,
                     ),
                 ),
             ),
         ));

         $this->inputFilter = $inputFilter;
     }

     return $this->inputFilter;
 }
}

和Module.php ,我認為index.phtml不需要在這里發布。

 namespace Auth;

 use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
 use Zend\ModuleManager\Feature\ConfigProviderInterface;

 class Module implements AutoloaderProviderInterface, ConfigProviderInterface
 {
 public function getAutoloaderConfig()
 {

 }

 public function getConfig()
 {
     return include __DIR__ . '/config/module.config.php';
 }
 }

默認安裝中不再包含Zend\\Ldap 由於ZendFramework-Team已將zendframework拆分為多個組件,因此不再需要全部組件。 Zend\\Ldap是“不需要的”之一,因為它對ext/ldap有着嚴格的依賴性,因為沒有PHP的LDAP擴展就無法使用它。 有關詳細信息,請參見https://github.com/zendframework/zf2/issues/7569

因此,您應該從項目的基本目錄中運行composer require zendframework/zend-ldap ,並且應該已啟動並正在運行。 現在,安裝后您將獲得建議。

zendframework/zendframework suggests installing zendframework/zend-ldap (zend-ldap component ~2.5.0, if you need LDAP features)

LDAP是zf2核心的一部分。

如果您對類名有疑問,那么您的自動加載器配置或不正確的類名路徑可能會出現問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM