2

I created an class extension of Zend_Controller_Action and added some user defined methods, which will be accessed from any controller so forth.

Every thing is working fine, until I use Zend Tool to create a new Action, as this time The Zend tool will not find out my extended class.

Error Message:

Fatal error: Class 'CMS_Zend_Controller_Action' not found in....

That is the class which extends Zend_Controller_Action and the one extended by other controllers like indexController.

How to make the class discoverable. Do I have to include each and every folders, like my classes are? Does zend does that? I dont think so. How does it do it?

wanovak
  • 6,117
  • 25
  • 32
Starx
  • 77,474
  • 47
  • 185
  • 261
  • Where in your application is the CMS_Zend_Controller_Action located? I'd also recommend against including 'Zend' in your class names - the convention would be to use your own namespace instead of the word 'Zend', not in addition to it. So you'd have CMS_Controller_Action instead. – Tim Fountain Jul 19 '11 at 14:53
  • @Tim Fountain, I am extending Zend_Controller_Action, So I preferred to indicate that as well. And also because, I also have my own CMS_Controller_Action too – Starx Jul 19 '11 at 15:08
  • Just a confirmation: I was able to replicate this using Netbeans+Zend Framework Support on Windows. While debugging I realized that Zend_Tool does not use the application bootstrap mechanisms (at least not when I tested this). – madflow Jul 19 '11 at 15:13
  • @madflow, exactly. That might be the problem. How to fix it? – Starx Jul 19 '11 at 15:16

2 Answers2

0

Simple. :-p If it can find your core controllers, then you just need to include the path to your extended controllers.

http://php.net/manual/en/function.set-include-path.php

set_include_path(path_to_your_extended_classes) in your index.php, aka routes file.

Steve Nguyen
  • 5,854
  • 5
  • 21
  • 39
  • I have mentioned about this in my question too. I find this option, very limited. As I will have to include every needed folders then. If I have to go this way, I would like to know if there is a way where I can mention to include every folder inside a folder. What does Zend framewook do by the way, set_include_path every library folder. – Starx Jul 19 '11 at 14:45
  • @Starx It'll recursively look in the folder. so set include path `a/` will also include `a/b`, `a/b/c`, `a/d`...etc.. Try it out. It'll take less than a few minutes. – Steve Nguyen Jul 19 '11 at 14:48
  • In that case, it is already included `set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), )));` all the library including CMS and Zend is including inside this folder – Starx Jul 19 '11 at 15:04
  • @Starx why is there a comma after get_include_path()`,` ? – Steve Nguyen Jul 19 '11 at 15:07
  • Array does support a extra comman at the end. Check [this](http://stackoverflow.com/questions/3950451/putting-comma-at-end-of-array-is-it-a-convention) – Starx Jul 19 '11 at 15:12
  • @Starx it still can't find your extended controllers? Do you have your controllers in the include path? – Steve Nguyen Jul 19 '11 at 15:14
  • If what you said about `a/ will also include a/b, a/b/c`, is true then yes, it should. But it is not .... – Starx Jul 19 '11 at 15:19
  • I don't use Zend_Tool anymore but remember there is a config ini file. Have you tried adding the namespace like with the application.ini? Plus there is this constant ZF_STORAGE_DIR – Adrian World Jul 19 '11 at 16:08
  • @Starx do you have an .htaccess setup? for routing to your index.php file. – Steve Nguyen Jul 19 '11 at 16:11
  • @Adrian, Not in config.ini but a namespace is setup from the bootstrap. – Starx Jul 19 '11 at 17:40
  • @FinalForm, yes, I have .htaccess file to route to my index.php. It is the default .htaccess file that comes up with zend framework. – Starx Jul 19 '11 at 17:42
0

I think what you are trying here is not what Zend_Tool is about.

As much as I understand your question and setup you have created a class in your library. Of course, you can extend Zend_Controller_Action with lots of your own classes in your own library/libraries (I do that, too). Adding an action to such a class is maybe unusual but a problem for Zend_Tool for one specific reason.

Zend_Tool I believe is only about the well known structures like /application and same for what is inside /modules. If you create a Controller Class Zend_Tool will do some work for you like adding required folder structure to your /application or /modules folder. Same with action method which require view files. Having a Controller Class in your library does not (should not) need all that and hence is not build into Zend_Tool. I think whatever class you create in your library is not supported in Zend_Tool.

Adrian World
  • 3,118
  • 2
  • 16
  • 25