473,840 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MVC Patterns on the Web and Static Resources

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("script s", $this->getScripts() );
...
echo $tpl->render("page.p html");
}

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!

May 28 '07 #1
1 1982
Sean Quinn schreef:
(..) 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.
(..)
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.
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
function.
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.
They can, see http://nl2.php.net/manual/en/function.header.php

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.

(..)
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?
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.
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?
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.
>
Thanks in advance!
Thanks for a chance to give my opinion on the ZF.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

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.
May 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1615
by: NKOBAYE027 | last post by:
Hi Folks: Can anyone direct me to a good resource on design patterns. I'd like to use them for a project I'm working on regarding set theory - in particular I'd like to use the Decorator pattern to present an interface for a 'sortable' set template derived from the default unsorted set template. And, I'd like to have a Factory pattern used as a source of the set objects. I am a relative newbie to this sort of design approach, so if I'm...
5
1864
by: Coder-X | last post by:
Hi, i have a few questions i would like to ask : 1 - Where can i find good design patterns resources for .NET ? 2 - What's the best design pattern for a windows database application ( multiuser ) ? 3 - I'm trying to develop a simple database application . I'm thinking of defining a class for every table in the database. Is this a good design practice ?
6
6604
by: Dolphin White | last post by:
For example, I allocate some unmanaged resources in the static constructors, then how can I properly release the resource before the application exit? thx!
1
2379
by: Jay | last post by:
The GOF text is widely considered the definitive book on the topic. Design Patterns: Elements of Reusable Object-Oriented Softare, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Note, all the examples are in C++ but you can get through them with a little work.
4
1931
by: Frazer | last post by:
hi are there any good samples illustrating design patterns in C#? builder, adapter, facade etc. i found a few but the reviews of that article were bad. eg http://www.codeproject.com/csharp/csdespat_1.asp#xx327127xx thnx
12
2591
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in advance, Joe
2
2607
by: Carlo Stonebanks | last post by:
I have the infamous GoF Design Patterns boo - it's been sittin gon my shelf for years. I have a huge reading list and find this book a rather dry read and am always putting it off. I have recommendation for "Head First Design Patterns" book, but it's aimed aimed at Java developers. I'd rather have a book that has a "For Dummies" readability that that hopefully exploits C# and .NET features and (oh, please, please, please) includes a CD...
69
3258
by: MQ | last post by:
Hi all I am just wondering how most people implement cleanup in C functions. In particular, if the function opens a number of resources, these need to be released properly should an error occur at any point in the function (as well as at the end if successful). C++ has exceptions, the only way I can see to do this neatly in C is to use goto statements. Is my method of implementing cleanup good, or are their better ways. Here is an...
1
2985
by: aj | last post by:
I'm sure some (maybe many) of the folks in the group are familiar w/ the Gamma/Helm/Johnson/Vlissides Design Patterns book (often call Gang of Four or GoF). My question: Is there any such thing for databases? I don't simple normalization, but higher-level stuff. Anyone have pointers to any books, papers, ideas, etc?? TIA
0
9863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9702
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7845
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7023
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4080
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.