|
Posted by Sean Quinn on 05/28/07 03:07
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:
http://www.example.com/ or http://www.example.com/index.php
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:
http://www.example.com/index/ or http://www.example.com/index.php/index
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
parent.
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
instance:
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
yet?
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!
Navigation:
[Reply to this message]
|