2

I try to migrate application from version 1.11.2 to 1.12.1. I simply replaced Zend folder which contains 1.11.2 with Zend folder which contains 1.12.1. Application that worked in 1.11.2 doesn't work in 1.12.1, it can't load classes:

Fatal error: Class 'Plugin_AccessCheck' not found in 
C:\git_reps\mailable\application\Bootstrap.php on line 32

I have file with plugin in application/plugin folder and it worked in 1.11.2. Could you please tell me why my application doesn't work in 1.12.1 and how to make application work in new version? If I turn off plugin, it can't find other classes for example my models.

Here is fragmenet from application.ini:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view.doctype = "HTML5"

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

autoloaderNamespaces[] = "Common_"
autoloaderNamespaces[] = "Shanty_"
resources.view.helperPath.Common_View_Helper_ = "Common/View/Helper/"


bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

appnamespace = ""

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

Here code to register pluging:

/**
 * Init plugins
 */
protected function _initPlugins()
{
    $fc = Zend_Controller_Front::getInstance();     
    $applicationPart = getenv('APPLICATION_ENV_PART');      
    switch($applicationPart) {
        case 'subscribe':
            $fc->registerPlugin(new Plugin_SubscribeAccessCheck());
            return;             
            break;
        default:
            $fc->registerPlugin(new Plugin_AccessCheck());              
            break;      
    }   
}

When I turn off plugin in BootStrap, it can't find other files for example models.

Oleg
  • 2,733
  • 7
  • 39
  • 62

2 Answers2

2

If the suggest of @Marc not work try add the following line in application.ini:

resources.frontController.plugins.accessCheck = Plugin_AccessCheck

in Bootstrap.php:

/**
 * @return Zend_Application_Module_Autoloader
 */
protected function _initAutoload()
{
    $autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH));
    $autoloader->addResourceType('plugin', 'plugins', 'Plugin');
    return $autoloader;
}

This works if the file is in the following path: /app/application/plugins/AccessCheck.php

JellyBelly
  • 2,451
  • 2
  • 21
  • 41
  • I update my post adding code that is used to register plugin and it worked it worked in 1.11.2 and ealier versions. – Oleg Jan 16 '13 at 09:44
  • Do you mean that something change in 1.12.1 that application working in previous version don't work any more? – Oleg Jan 16 '13 at 09:49
  • Why do I need resources.frontController.plugins.accessCheck = Plugin_AccessCheck if I register it in bootstrap as I wrote in post? – Oleg Jan 16 '13 at 09:50
  • your function "Init plugins" it'ok! makes the same thing `resources.frontController.plugins.accessCheck = Plugin_AccessCheck`, but you must add my `_initAutoload ` in your bootstra, otherwise zend does not know where your plugins live! – JellyBelly Jan 16 '13 at 10:21
  • My plugins are in application/plugins folder. I wonder why application worked in previous versions and doesn't work now. application.ini and framgrament from bootstrap worked ok in 1.11.2. You might see that I had in application.ini: appnamespace = "" – Oleg Jan 16 '13 at 10:36
  • I wonder what changed in 1.12.1 that code doesn't work any more. – Oleg Jan 16 '13 at 10:38
  • It looks like appnamespace = "" from application.ini doesn't work in 1.12.1 for some reason. I don't know if I have problems similar that is described here: http://framework.zend.com/issues/sr/jira.issueviews:searchrequest-fullcontent/temp/SearchRequest.html?jqlQuery=project+%3D+ZF+AND+component+%3D+Zend_Application+ORDER+BY+updated+DESC%2C+priority+DESC%2C+created+ASC&tempMax=1000 – Oleg Jan 16 '13 at 10:45
  • It looks like I add only 2 lines of your code, it works:protected function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader(array('namespace' => '', 'basePath' => APPLICATION_PATH)); return $autoloader; } – Oleg Jan 16 '13 at 10:54
  • I mean it seems it works only with 2 lines in __initAutoload without this like: $autoloader->addResourceType('plugin', 'plugins', 'Plugin'); – Oleg Jan 16 '13 at 10:55
  • I believe that zend has changed the way of doing the autoload. But to know precisely should read all the change log. – JellyBelly Jan 16 '13 at 11:13
1

From the error, php can't auto load the class Plugin_AccessCheck, I'm guessing you have a Plugin directory in your lib folder with a php file called AccessCheck.php

Try adding

autoloaderNamespaces[] = "Plugin_"

to your application.ini or manually do an include for that file

If this isn't the case, you have mis-named your class Plugin_AccessCheck. possible solutions are moving it to your common lib Common/Plugin/AccessCheck.php and renaming the class to Common_Plugin_AccessCheck

Marc
  • 416
  • 3
  • 8
  • As I wrote before my plugin is in application/plugins folder, not my lib folder, I think it's strangard way of storing plugins in Zend_Framework. And could load it in 1.11.2. – Oleg Jan 16 '13 at 04:41
  • Even If I turn off plugin in BootStrap, my models classes can't be found in Zend_Framework 1.12.1. – Oleg Jan 16 '13 at 04:48
  • if your plugin is in application/plugins, your class should be called Application_Plugin_WebAccess – Marc Jan 16 '13 at 15:15
  • As you see in my application.ini I have: appnamespace = "", so it allow to use Plugin_AccessCheck. It worked in previous version, but doesn't work in 1.12.1 for some reason. – Oleg Jan 16 '13 at 15:17
  • so a better question to ask is how to have a blank appnamespace. – Marc Jan 16 '13 at 16:57
  • As you can see from application.ini in my post, I used appnamespace = "" and it worked in versions ealier 1.12 but it looks like it doesn't work in 1.12.1. It looks like added _initAutoload as in answer above (lines 1 and 3 from it) seems to solve this question. But what cause problem in version 1.12.1 is not clear yet. – Oleg Jan 17 '13 at 04:09