ZendFatal错误:找不到类'Zend \ Ldap \ Ldap' [英] ZendFatal error: Class 'Zend\Ldap\Ldap' not found

查看:105
本文介绍了ZendFatal错误:找不到类'Zend \ Ldap \ Ldap'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我要按照

https://zf2.readthedocs.org/en/最新的/用户指南/skeleton-application.html

我只是将相册"模块替换为验证"模块,并使用示例代码进行Ldap验证

I just replace the 'Album' module with a 'Auth' module and use the sample code for Ldap autentication

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

但是当我提交带有登录数据的表单时,Zend无法找到Ldap类,但出现此错误.

but i'm getting this error where Zend can't find the Ldap class when i submit the form with the login data.

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

Fatal error: Class 'Zend\Ldap\Ldap' not found in C:\wamp\www\sade\vendor\zendframework\zend-authentication\src\Adapter\Ldap.php on line 139

我正在使用composer,用于zend框架和用于模块的atuoloader,我已经遇到了与找不到一个类有关的错误,但我自己的类,而不是Ldap之类的Zend类.

I'm using composer, for the zend framework and the atuoloader for the modules, i already have errors related a class not found but my own classes, not Zend classes like Ldap.

谢谢.

这是文件和文件夹的结构

Here is the structure of the files and folders

/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 (位于模型"文件夹中,用于我稍后可能实现的过滤器)

Auth.php (inside Model folder, for filters that i may implement later)

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不需要在此处发布.

And Module.php, i don't think that index.phtml needs to be posted here.

 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

Zend\Ldap is not included any more in a default installation. As the ZendFramework-Team has splitted the zendframework into multiple components not all of them are needed any more. And Zend\Ldap is one of the "not needed" ones as it has a hard dependency on ext/ldap as you can't use it without the LDAP-extension of PHP. For details on that have a look at https://github.com/zendframework/zf2/issues/7569

因此,您应该从项目的基本目录中运行composer require zendframework/zend-ldap,并且应该已启动并正在运行.现在,安装后您将获得建议.

You should therefore run composer require zendframework/zend-ldap from the base-directory of your project and you should be up and running. By now you get that as a suggestions after the installation.

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

这篇关于ZendFatal错误:找不到类'Zend \ Ldap \ Ldap'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆