Zend Autoloader unable to find existing file - php

I'm having an unusual autoloading problem with my Zend website. Up until now autoloading has been working a treat. Now though, I added a new file the project and autoloading just can't find it. I've reduced the problem to the minimal test case and was wondering if anyone could help me out.
In my website I have a the usual directory structure, like so:
site/
application/...
library/
Zend/...
PHPUnit/...
Ext/
Extras/
Test.php
Service/
Test.php
I've correctly set up auto loading (as per other helpful comments on StackOverflow) and registered the Ext_ namespace, which is proved by being able to correctly instantiate Ext_Extras_Test.
The problem comes when I try to instantiate Ext_Service_Test. Autoloading "failed to open stream". I've checked the correct spelling, listed the directory contents using find, ls, and the file explorer to make sure that the file exists in the correct place.
I just can't get it to &^%%£* find the file! Does anyone have any clues?

Found it you are trying to override a resource autoloader, even though it's not specified I'm pretty sure this will effect all namespaces:
42.3.2. The Module Resource Autoloader Zend Framework ships with a concrete implementation of Zend_Loader_Autoloader_Resource that
contains resource type mappings that cover the default recommended
directory structure for Zend Framework MVC applications. This loader,
Zend_Application_Module_Autoloader, comes with the following mappings:
forms/ => Form
models/ => Model
DbTable/ => Model_DbTable
mappers/ => Model_Mapper
plugins/ => Plugin
services/ => Service
views/
helpers => View_Helper
filters => View_Filter
As an example, if you have a module with the prefix of "Blog_", and
attempted to instantiate the class "Blog_Form_Entry", it would look in
the resource directory's "forms/" subdirectory for a file named
"Entry.php".
When using module bootstraps with Zend_Application, an instance of
Zend_Application_Module_Autoloader will be created by default for each
discrete module, allowing you to autoload module resources.

Related

Yii 1.1.16 : components folder is not accessible all over the application in Ubuntu

The error I'm getting is:
include(widgetHomeMenu.php): failed to open stream: No such file or directory
same for all other widget views I'm rendering on other pages.
The file is in my components directory. I guess the directory is not accessible because the file exists there. Plus I've given permission to all the files in /var/www.
Also in my config.php file, there is:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
So, I guess the config is loading components as well.
Not sure where is the problem exactly. No problems with case sensitivity, its correct and the filename is correct as well. The application is working flawlessly on several Windows PC using xampp.
Will be thankful for any help.
I found the problem. It was ultimately related to case sensitivity even though I mentioned above that there was no such problem.
I was loading the widget like this:
<?php $this->widget('widgetDashboardMenu');?>
where I thought that widgetDashboardMenu was the name of the view that was about to render (my bad). This was actually the controller inside components named WidgetDashboardMenu which then loaded widgetDashboardMenu.
So, changing w to W solved the problem for me.
<?php $this->widget('WidgetDashboardMenu');?>

Can't import Vendor class into Component in CakePHP 2.5.1

I've been looking at all the related questions of this topic and none of the solutions provided (usually App::import() ) have worked for me, maybe because I have a different configuration, which is the following:
I have a regular cake installation which loads components from an external folder (so outside this installation). That works perfectly, even for the component I'm trying to use now (it works fine until I try to load the Vendor class). This Vendor class I want to have it outside the Cake installation as well (same as with the components). This is how this installation looks:
[root]
.......[shared_resources]
......................................[CakePHP]
........................................................[Components]
..............................................................................MyCustomComponent.php
........................................................[Vendor]
....................................................................[MyVendor]
......................................................................................MyVendor.php
......[MySite]
................... [cakephp typical folder structure]
In my site's bootstrap.php file I have App::build(array('Controller/Component' => array(dirname(ROOT) . '/shared_resources/CakePHP/Component/'))); in order to be able to load that component in any controller, which works fine, any component I put in that folder loads and works without issues.
Now, I'm trying to load the MyVendor class in the MyCustom component, but I can't get it to work, no matter what I try I keep getting class not found errors when trying to instantiate it.
I've tried using php's and Cake's require(), import(), App::import() and App::uses() with all possible combinations of paths (absolute and relative) without any success, puttin them before the declaration of the component class and inside the method that actually uses the vendor class. The last one I've tried is App::import('Vendor', '/absolute/path/to/shared_resources/Vendor/MyVendor/MyVendor.php'); for example.
I've also tried using App::build(array( 'Vendor' => array(dirname(ROOT) . '/shared_resources/CakePHP/Vendor/'))); in the bootstrap file, like with the components.
I don't know what else to try, any help would be much appreciated!!!
Oh, I've check with PHP that the file Vendor class file exists in that path too.
According to your folder structure,
To access your MyVendor.php, you should write like this
App::import('Vendor', 'MyVendor', array('file' => 'MyVendor/MyVendor.php'));
For more information, read http://book.cakephp.org/2.0/en/core-utility-libraries/app.html

Autoloading module level classes and config files in symfony

I am trying to auto-load classes from the "lib" directory inside of one specific module directory.
I have tried everything but to no avail...
One of the classes I would like to load is a class called visUser which inherits from myUser I have already made a factory.yml file in myapplication/modules/mymodule/conf but it doesn't load...
I am doing something wrong? or module level configuration files are not suported?
I am using symfony 1.2 with propel.
Factories are an application specific file and cannot be overloaded on the module level. It's a weird idea anyway.
Read the config handlers file to see what files are supported on the modules level configuration (symfony/lib/config/config/config_handlers.yml).

ErrorController: worth it to move it to a default module

I'm trying out the module-based architecture for my application, where the default module is what used to be the main application before.
modules/
default/
firstmodule
secondmodule
thirdmodule
Each module has its models, views, controllers. This is the default module as an example.
default/
models
views
controllers
IndexController
My problem is with the ErrorController that zend creates by default at application/controllers/ErrorController.php. I'd like to move it into the default module's controllers folder, but I wonder if it needs any special treatment, being the ErrorController and all?
Should I move it to modules/default/controllers/ErrorController.php,
or should I leave it at application/controllers/ErrorController.php
Edit: If I move it to default/controllers, then each of the other modules would not have an ErrorController. Does that mean that I'd have to define one for each module since the application itself doesn't have an ErrorController? and is it worth it to define one for each module?
How come you still have things in the old structure, rather than all the leftovers moved the default module.
My directory structure is like so:
/application/data/
/application/config/
/application/modules/balcms/controllers/
/application/modules/burn/controllers/
/application/modules/default/controllers/
/library/
/public/
...
Only special treatment is ensure your prefix is correct for your autoloader (this can be optional).

PHP: Storing objects in a Symfony plug-in module's lib/ directory

I am building a Symfony project, and have created a new plug-in named sfUtilsPlugin. I currently have a directory structure that looks like this:
sfUtilsPlugin/
modules/
sfSearchLucene/
actions/
config/
lib/
templates/
Now, in the sfUtilsPlugin/modules/sfSearchLucene/lib directory, I have an object called sfLucene. The idea was that this object is accessible from the Symfony auto loading mechanism, so that it can be instantiated from anywhere within the application.
However, simply adding the sfLucene.class.php file to the sfUtilsPlugin/modules/sfSearchLucene/lib directory does not appear to add it to the autoloader.
Does anyone out there know why this might be happening? Perhaps it is just not possible to automatically use objects stored in this location inside Symfony.
Any advice is appreciated.
Because you are adding this class in lib subdirectory of module sfLucene, it will be autoloaded only if current module is sfLucene.
You have two options:
put this class somewhere into sfUtilsPlugin/lib directory;
require them every time you need it

Categories