0

I'm looking for some assistance in properly setting up my application's autoloader, bootstrap, etc. to achieve something similar to the following Application file structure:

/application
    /configs
        application.ini
    /controllers
    /models
        /User.php    // Model_User
    /modules
        /blog
        /admin
            /controllers
                /IndexController.php
            /models
                /User.php    // Model_User
            /views
                /blocks
                    /menu.phtml
                /helpers
                    /CoolMenu.php
                /layouts
                    /layout.phtml
                /scripts
                    /index
                        /index.phtml
                        /list.phtml
                /themes
                    /some-custom-theme
                        /helpers
                        /layouts
                            /layout.phtml
                        /scripts
                            /index
                                /index.phtml
                                /list.phtml
                            /users
                                /index.phtml
                                /list.phtml
                                /list.ajax.phtml
    /views
        /blocks
        /layouts
        /scripts
        /themes
            /some-custom-theme
                /blocks
                /layouts
                /scripts
                /helpers
    /Bootstrap.php
/library
    /Zend
    /MyCompany
        /Model
            /Api
                /Abstract.php
/public
    /css
    /js
    /images
    /themes
        /some-custom-theme
            /css
            /js
            /images

The idea here of course is that the basic "application" structure can be overridden by modules, and the view can also be overridden at either level by themes.

Some my question is, while sticking as closely as possible to Zend Framework concepts and "ideals", keeping things as simple and elegant as possible and using, as much as possible, a "mainstream" ZF approach, how would you handle the following situations?

  1. How would you set up the Autoloader and include paths to cleanly handle application controllers, models, views, and other application resources that may be (but aren't necessarily!) overridden by module resources?

  2. How would you initialize the View to be able to override the default view resources in each of these scenarios with theme resources?

I understand this is a fairly general, open-ended request, but I've been researching and experimenting on this for a couple of days now, I've tried a dozen or more different approaches and I just can't seem to get it all working. Everything I try seems to break something else, or I just can't find the right methods in ZF, or whatever. I'm kind of at the point where I'd really just like to hear some fresh ideas from a fresh perspective. I don't expect a complete solution, I just need some solid ideas to get me thinking in a more useful direction!

PS: I'm using ZF 1.11

Brian Lacy
  • 18,785
  • 10
  • 55
  • 73
  • read this: http://stackoverflow.com/questions/7928771/zend-framework-doctrine1-2-project-structure-with-more-modules/7969590#7969590 for setting different layout! ;) – JellyBelly Nov 08 '11 at 15:55

1 Answers1

1

The view paths is the easy[1] bit. You can add additional script paths and these are checked in LIFO order, so for each module you'd have the standard path and then the theme path. I'm sure I've posted code for this to Stackoverflow in the past so if you search old questions for people trying to do theme stuff you should find it. Layouts work in a similar way, although I've only ever done overrides for these at an application level, not at a module level.

For models, I can't see in your example exactly where an overridden model would live, but to answer generally, PHP will do most of the work for you with the include path. So you just add your 'override' directory to the start of the include path and PHP will check each one until it finds the class. If the requirements are a bit more complex than that you could consider writing your own autoloader (see: http://framework.zend.com/manual/en/zend.loader.autoloader.html#zend.loader.autoloader.interface ).

Controllers are the awkward bit as (from what I remember) these are not autoloaded in the conventional sense, their filename and location is simply assumed based on the path supplied to the front controller. It would be fairly easy to allow all of the controllers for a module to be overridden by checking in your bootstrap whether something like /modules/admin/themes/foo/controllers exists and if so, using that as the module's controller path instead of /modules/admin/controllers. That would be an all or nothing approach though - if you wanted to override a controller for a module you'd have to do them all. You might be able to find a nicer way if you dig around in the Zend_Controller_Front class.

[1] Easy being relative here - all of this stuff would require you to be pretty comfortable with ZF.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • Thanks for the ideas, this was exactly the kind of thing I was looking for. Also, I *may* have found the code you were referring to, but I'm not sure yet: http://stackoverflow.com/questions/6069488/zend-overwrite-default-view-object – Brian Lacy Nov 08 '11 at 15:52