خطأ "لم يتم تحديد الوحدة الافتراضية" في تطبيق Zend Framework

StackOverflow https://stackoverflow.com/questions/733120

  •  06-09-2019
  •  | 
  •  

سؤال

أنا بصدد جعل ملف bootstrap.php الخاص بي أكثر تنظيمًا، ولكن بعد أن أضع كل شيء في طرق ثابتة منفصلة، ​​لا أستطيع تحميل أي صفحة خارج وحدة تحكم الفهرس.على سبيل المثالإذا حاولت فتح

http://localhost/zftutorial/login/index

انا حصلت

    Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 
'Invalid controller class ("Login_IndexController")' in C:\Program 
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php:341 
Stack trace: #0 C:\Program 
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php(255): 
Zend_Controller_Dispatcher_Standard->loadClass('IndexController') #1 C:\Program 
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Front.php(934): 
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), 
Object(Zend_Controller_Response_Http)) #2 C:\Program 
Files\VertrigoServ\www\zftutorial\public\index.php(18): Zend_Controller_Front->dispatch() 
#3 C:\Program Files\VertrigoServ\www\zftutorial\public\index.php(138): Bootstrap::run() #4
 {main} thrown in C:\Program 
Files\VertrigoServ\www\library\Zend\library\Zend\Controller\Dispatcher\Standard.php on 
line 341

وفي ملف التمهيد الخاص بي يبدو أنني قد حددت المكان الذي يمكن العثور فيه على وحدات التحكم:

public static function setupFrontController()
{
    self::$frontController = Zend_Controller_Front::getInstance();
    self::$frontController->throwExceptions(true);
    self::$frontController->returnResponse(true);
    self::$frontController->setBaseUrl('/zftutorial');

    self::$frontController->setControllerDirectory(
        array(
            'default' => self::$root . '../application/controllers',
            'admin' => self::$root . '../application/controllers',
            'index' => self::$root . '../application/controllers',
            'login' => self::$root . '../application/controllers',
            'user' => self::$root . '../application/controllers'
        )
    );

    self::$frontController->setParam('registry', self::$registry);

}

ربما يتعلق الأمر بشيء ما فيما يتعلق بالتوجيه، لكن تطبيقي كان يعمل بشكل جيد مع التوجيه الضمني من قبل، على سبيل المثال.عملت وحدات التحكم الأخرى بشكل جيد أيضًا.ما هو مصدر الخطأ أعلاه؟كيف يمكنني اختباره/العثور عليه/إصلاحه؟

هل كانت مفيدة؟

المحلول

عند النظر إلى تتبع المكدس الخاص بك، فإن الخطأ هو فئة وحدة التحكم غير صالحة ("Login_IndexController")

يشير هذا إلى أن فئة Login_IndexController غير موجودة.

يجب أن يكون لديك ملف يسمى IndexController.php في دليل وحدة التحكم الخاصة بوحدة تسجيل الدخول.لن تعمل البنية الموجودة لديك حاليًا لأنه لا يمكن أن تحتوي وحدتان على وحدة تحكم بنفس الاسم.تغيير الهيكل إلى

self::$frontController->setControllerDirectory(
        array(
            'default' => self::$root . '../application/modules/default/controllers',
            'admin' => self::$root . '../application/modules/admin/controllers',
            'index' => self::$root . '../application/modules/index/controllers',
            'login' => self::$root . '../application/modules/login/controllers',
            'user' => self::$root . '../application/modules/user/controllers'
        )
    );

قم بإنشاء IndexController.php في self::$root .'../application/modules/login/controllers وتأكد من تسمية الفصل Login_IndexController

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top