MVC Patterns on the Web and Static Resources

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all,

This may have a really simple answer to it, but I can't seem to figure
it out no matter how much I think about the problem.  I'm working with
an MVC framework (presently the most recent version of the Zend
Framework 0.93, but no too committed with the project to prevent me
from switching gears to a different framework), but I am having one
heck of a time when attempting to reference static resources such as
javascript scripts, or style sheets, I haven't tried images but I
suspect I will have problems with those as well.

I am currently running an Apache 2.0 web server through the XAMPP
application (simpler to setup), and in my application root directory I
have a .htaccess file with rewrite rules to redirect the browser's URI
to the proper one (base URL's index.php file, effectively the
bootstrap file)

It seems to be a [interpreted] relative path issue as when executing
the front controller off of a web address similar to the following: or

The static resources are presented properly.  Using the MVC framework,
the default action for the above front controller is the index Action--
now if I explicitly tell the browser what action to execute and I tell
it to execute the index action like so: or

My static resources suddenly disappear.  The only explanation for this
that I have, is the fact that no longer would the styles be found
under the ./styles directory but the ./../styles directory.  Thus,
despite the fact that the system is getting the content in both
examples above (the one that works, and the one that doesn't) from the
same action controller, the only thing different is the interpreted
path shown in the URL bar.  I can't figure out whether it is something
I am doing wrong, or whether it is the nature of the MVC architecture
that paths to static resources can't be derived from the Front
Controller in the root directory.  It should be noted that I have
extended both Front and Action controllers, though the constructor
behavior of each extended class behaves the same exact way as the

I'm setting the styles as an array of paths that are set in the action
before a view is rendered, there could be a case where certain styles
(or scripts) were used by one page and not by another thus, while
these resources are static they are being assigned dynamically... for

  public function indexAction()
      $tpl = new Zend_View();
      $this->addStyle("./resources/styles/style1.css");  //
convenience function
      $tpl->assign("styles", $this->getStyles() );
      $tpl->assign("scripts", $this->getScripts() );
      echo $tpl->render("page.phtml");

1) Is the Zend Framework stable, and developed enough to use over
CakePHP, Solar, or any other framework out there, and what would
people recommend if they feel that Zend's framework isn't quite ready
2) Under ZF, or any other framework for that matter, while it may be
the single index.php file that gets executed to initiate the
Controllers and Views, why wouldn't it have the correct path for a
static resource always in the same place?  Is this a shortcoming of
the MVC architecture, the framework implementing it, or my own short
sighted implementation?

Thanks in advance!

Re: MVC Patterns on the Web and Static Resources

Sean Quinn schreef:
Quoted text here. Click to load it

Hi Quinn,

I agree. The problem is url rewriting. Like Zend Framework i use url  
rewriting (but only for websites) so i also have that problem (for  
websites). My solution is to make all paths to static resources  
absolute. With phpPeanuts this is simple, as it has a function  
pntGetBaseUrl and i have standard locations for the static resources. In  
the rare case i deviate from this i can override the standard function  
on a single place in the website code and use an adapted version of the  

 > Thus,
Quoted text here. Click to load it

They can, see

But do you want to? All bytes of those resources will be streaming  
through your php scripts, using processor cycles for something the  
webserver software was optimized to do efficiently.

Quoted text here. Click to load it

Imho ZF does not really do very much. PhpPeanuts comes with a whole  
bunch of generic Pages, Parts, Actions and Dialogs, so (for database  
applications) it gives you much more of a structure to build on (and  
much more to learn about - larger investment, more profit if it fits  
your purpose).

The ZF may be a nice start for building CMS based websites, but there  
are complete CMS's available that give you a much bigger headstart. I  
guess there must be some that support url rewriting for search engine  
friendly url's too.

Quoted text here. Click to load it

It's ZF using url rewriting, not MVC. Your implementation will have to  
compensate. It must be a common problem, Zend should have documented how  
to handle it.

It is not necessary to use url rewriting for the MVC Architecture.  
PhpPeanuts uses a single index.php for each 'application' and does the  
rest with parameters (normal ones, behind the question mark). How the  
parameters are interpreted is basically up to the front controller and  
it can manipulate the copy of their values it passes to the following  
controller (recursively), so it is about as flexible as with ZF.

Because phpPeanuts does not depend on url rewriting it does not have  
this problem resources problem. Furthermore it can be used with IIS and  
(other) servers that do not support url rewriting.

However, it has some support for using url rewriting, but it is only  
meant for specific applications that require custom conrollers/handlers  
anyway, see my above remark about websites.

Quoted text here. Click to load it

Thanks for a chance to give my opinion on the ZF.


Henk Verhoeven,

N.B. phpPeanuts is an application framework, not a CMS. You can use it  
to build a CMS and build websites with the resulting CMS, but the  
tutorials will be of little help. If you need a CMS, you better look for  
a CMS.

Site Timeline