views:

62

answers:

1

In a Zend Framework 1.10 application, I have a controller UsersController in a module api and in the index view of that controller I would like to reference a static asset (like a javascript file). How can I do that without putting the file in the main public?

so, we have a directory setup like this:

zfproj/
../application/modules/api/controllers/UserController.php ../application/modules/api/views/scripts/users/index.phtml
../application/modules/api/public/javascript/apimodule.js
../application/controllers/
../application/views/
../public/

I want to be able to include the apimodule.js in a view (in this case the users/index view). Ideally, this would able to be done without adding anything into zfproj/public

The intention behind this is to create a module that can be deployed into a ZF 1.10 application that is completely self-contained and does not require adding assets (like Javascript files) into the applications existing public/javascript files.

+3  A: 

Typically all your publicly accessible assets go in public. It's meant to be the web root of your application and typically you set the DOCUMENT_ROOT of your apache virtual host to this folder. I'm not sure why you'd want to store client files (javascript, css, etc) outside the webroot. Can you elaborate more on your directory/application structure (maybe hinting at the location of the file you want to include)?

Edit

What you're asking should be possible. To make a standalone module, I think you'd just move "api" inside the primary public folder and the module would have its own bootstrap or you'd have to do something in your primary bootstrap based on the module name ("api" in this case). You'd have to modify your include paths accordingly. You'd need to add an .htaccess file to protect your code directories in this case.

../application/controllers
../public/api/controllers
../public/api/javascript/apimodule.js
../public/api/index.php

You might also create a symlink in your public folder that points to the public folder of api. So,

../public/api > ../application/modules/api/public

This would allow access to public but protect your code files. One thing I often do is check out subversion external into the public folder that just points to the public folder of the module. My CMS looks like this:

application/modules/cms
application/modules/cms/ui (public facing cms UI)
public/ui (svn:external pointing to application/modules/cms/ui)

HTH give you some ideas.

Typeoneerror
I've added a more detailed explanation of the structure in the question.
Joshua Smith
Ok, that makes sense to me. Thinking about it...
Typeoneerror
the svn external I think is probably the way I'll go on this. Thanks for your comments, they are very helpful.
Joshua Smith