Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008, 05:51 PM
Junior Member
 
Join Date: Oct 2007
Posts: 26
Question Zend Framework 1.5 questions

Hello everyone,

I have a few questions that I've not been able to find answers for. Perhaps I've overlooked them.

I am using the following environment.

Ubuntu 7.10 32bit
MySQL 5.0
PHP 5.2.x
Zend Framework 1.5

I have started a test application, and I have broken down my application directory as follows:

Code:
application/
|-- config
|   |-- datasources.xml
`-- modules
    |-- admin
    |   |-- config
    |   |-- controllers
    |   |   |-- IndexController.php
    |   |-- models
    |   `-- views
    |       |-- filters
    |       |-- helpers
    |       `-- scripts
    |           `-- index
    |               |-- extract.phtml
    |               |-- index.phtml
    `-- default
        |-- config
        |-- controllers
        |   |-- IndexController.php
        |   |-- UserController.php
        |-- models
        |   `-- Persons.php
        `-- views
            |-- filters
            |-- helpers
            `-- scripts
                `-- index
                    |-- extract.phtml
                    |-- index.phtml
I have added the following line to my bootstrap so that I can add all of the controller directories to my path

Code:
  $frontController->addModuleDirectory($this->module_path);
This works great. The question I have is how do I add the "models" directory? I did not see a similar method for models. I am not well versed yet with regards to plugins and helpers (though I am trying. ;-) ) I understand the models directory is currently unknown. How can I add the "models" directory for each module without resorting to loading them all up into the include path? Is that possible? I assume it is.

For my next question.

In my 'library' directory, I have the Zend library directory. I also have my own Library, 'MyLibs'. How can I use Zend_autoload with, 'MyLibs'?


...and finally....

I am currently using the Zend_Registry to store database connection information for a particular application. I have also read about Globals.php and how to use it. I am assuming its better to use the registry as I am currently using it. Why would I use something like Globals.php vs the registry? Did I miss something as to why Globals.php is good or does Zend_Registry really replace it?

Any thoughts, insight or suggestions that anyone may have would be greatly appreciated.

Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-21-2008, 11:27 PM
Junior Member
 
Join Date: Mar 2008
Posts: 5
Default Adding models dirs to path

I used this trick to get around the problem:

Tony Ngo Zend Framework

(the post "Zend Controller Plugin - Model Include" from Tuesday, March 4th, 2008)

Put the code for the Kupo_Controller_Plugin_IncludeModel class in library/kupo/controller/plugin/IncludeModel.php and register it with your front controller in your bootstrapper index.php with

$frontController->registerPlugin(new Kupo_Controller_Plugin_IncludeModel());

It automatically adds all dirs named "models" to your include path, so you can get to them from your controllers.

Beware, this is my first day using Zend, and I'm pretty new to PHP! But it seems to work. From various forums it sounds like this is something that'll make it into the framework before long.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-22-2008, 02:12 PM
Junior Member
 
Join Date: Oct 2007
Posts: 26
Default

Thanks, I'll give it a try!

I've been able to pretty much get everything else working pretty easily with ZF thus far. I'm sure you'll come to enjoy it. :-)

Well, off to tackle my next challenge Zend_Auth and Zend_Acl. :-D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-22-2008, 09:12 PM
Junior Member
 
Join Date: Mar 2008
Posts: 5
Default

One thing that I think would really help newbies like myself is a good overview/tutorial on using modules with Zend from someone who's had a lot of experience with it. Seems like there's a list of standard things like this that you have to consider when using modules, and I see the same questions over and over in forum posts. I've been able to coble together enough to get it working, but I'm sure there are some best practices I'm missing that only come from experience. For now I'll just keep at it...

Eric
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-25-2008, 06:30 PM
Junior Member
 
Join Date: Oct 2007
Posts: 26
Default

ecmcn,

Yes, there are a few things, but ZF uses configuration over convention. This gives you a lot of flexibility. As you can see in my original post, I package my modules under the 'application/modules' directory. Others may choose to package their modules differently, thats great, thats how they prefer to deal with it.

In my opinion, there should be something akin to addControllerDirectory(). This would provide a consistent way to add module/model directories. Or perhaps addModuleDirectory() could take a configuration array or something else?

I've really come to like the flexibility to change my directory layout to suite my needs. I could never remember the layout of a Rails directory. ;-) (Though I do think Rails is slick), this way I don't have to remember the layout, just some basic rules.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-27-2008, 04:21 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

I prefer to just add the models directory by adding it to the include_path. This is the line of code in my bootstrap file:

PHP Code:
// Add the application/models/ directory to the include path
set_include_path('.' PATH_SEPARATOR '../application/models/' PATH_SEPARATOR get_include_path()); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-27-2008, 06:43 PM
Junior Member
 
Join Date: Oct 2007
Posts: 26
Default

notrub225,

Does the addControllerDirectory() method add the controller directory to the include path or does it do something different?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-28-2008, 01:55 PM
Junior Member
 
Join Date: Mar 2008
Posts: 12
Default

Quote:
Originally Posted by Howler9443 View Post
notrub225,

Does the addControllerDirectory() method add the controller directory to the include path or does it do something different?
I think, no.

From the API-docs:
addControllerDirectory
Add a single path to the controller directory stack
/friedhelm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-28-2008, 04:45 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
Originally Posted by Howler9443 View Post
notrub225,

Does the addControllerDirectory() method add the controller directory to the include path or does it do something different?
As friedhelm said, no it doesn't add it to include_path, but that isn't a directory you need to add to include_path.

include_path is a php thing, not a zend framework thing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:01 AM.