Reply to Re: Modifying and posting uri

Your name:

Reply:


Posted by shimmyshack on 05/06/07 14:24

On May 5, 4:48 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Jon Slaughter wrote:
> > "Jon Slaughter" <Jon_Slaugh...@Hotmail.com> wrote in message
> >news:UBX_h.21049$Um6.17337@newssvr12.news.prodigy.net...
> >> How can I take a uri passed to a interface script(a script that is called
> >> for every page request) modify it, do whatever, and then change the uri
> >> that the user see's to be whatever?
>
> >> Essentially I have a rewrite rule
>
> >> RewriteRule ^(.*)[/]?$ /Index\.php
>
> >> That calls index.php
>
> >> I can do $_Server['REQUEST_URI'] to get the uri but how can I modify the
> >> browser's uri that the user see's but also redirect the uri to something
> >> different.
>
> >> Basically I sorta want to write a rewrite handler of my own because I'm
> >> having a few issues with it. I'd rather use php to deal with it if
> >> possible.
>
> >> Thanks,
> >> Jon
>
> > Essentially what I would like to do is modify the uri with something like
>
> > $_Server['REQUEST_URI'] = '/MyPage/';
>
> > (as an example)
>
> > and it update the browsers uri but not effect anything else. (ofcourse if
> > they uset that uri I will need to make sure it maps to something)
>
> > I know I can use rewrite rules and I'm trying to I am having more problems
> > with them than it should be and I can handle it a lot easier in php(And
> > atleast debug it so I know why things are failing).
>
> You'll have to do this from the Apache end, not the client or your script.
>
> The URI in the browser is what the browser uses to request the page.
> You can't just change it without affecting what the browser requests.
> So you'll have to have Apache change the request to something different.
>
> You might be able to get some help in alt.apache.configuration.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I think what John's asking is how to implement an MVC style approach,
and he's clearly got it working to a degree. A simple rewrite is
already in place on the server which directs all requests to the
Controller which then takes the value of this URI, and uses it to
"forward" the content (View).
However the changing of the URI in the address bar isnt really what
you need.
Your rewrites should not "redirect" [ with 30x status] to the control
script, instead is uses the [L] flag to supress the address bar
change. The address bar however does change because all the links in
your application are generated by the application which understands
the layout model of your app.

So firstly it doesnt matter how the site is laid out, because your
controller can be setup [not the best way obviously] to go where your
content already is, BUT your Views, the html that you want to be
displayed should ideally not be heavily mixed with php that is written
for that page only and which contains absolute references to includes
[php classes etc...]. Instead you should hold the includes [database/
functions/classes etc...] all somewhere central, the references inside
the html [to things like images/css/js ...] should ideally all be
relative to the app root.
Then say you have a structure like this

/
/Music
Main.php
/Tutorials
MusicTheory.php
/Tutorials/MusicTheoryDefinitions.php

using an array of page->view templates it is obviously possible for
your controller to realise that when a request for
http://www.server.com/newapp/music/
(of the form /application/page/subpage/var1/var2/var3/ etc...)
comes in, it is to grab the URI, obtain the page, populate an array
with all the elements that the page should have (using the kind of
code that you probably have within /Music.php, and then find this
pages view [which is basically an empty html template with
placeholders for php variables] on the filesystem and include it,
which leads to the html output.

You are in a difficult situation because your code was written before
you thought about separation of code from content, so you have pages
which cannot just be included, or else various paths would be wrong,
but that would be one way to do this. Redirection using a header is
also one way but it will kill your page ranking - all those 302's) and
although changing the URLs as you wish doesnt address separation of
concerns (look and feel/programming ...)

My advice is to see this as a project, leave framesets behind,
concentrate on making the links generated by the MVC pattern human and
SE readable, and think about reducing the amount of repeated code
there is in each page, and try to abstract things like calls to mysql
and queries, in favour of building a query and passing it to a
function that makes the connection to the db and returns the query
results... after you have refactored your code, you will reap the
benefits of having implemented a true MVC pattern, and made your site
SO easy to maintain. (If you change to pgsql or decide to implement
security [login] you only have to update a single function, and a
small part of the model code. It might be work to refactor but it
really is worth it.

The Claw framework
http://claw.tigris.org/
which uses a Hierachical Model View Controller framework, is a great
example of what we are talking about, it too uses a single rewrite,
and then some decent code to abstract everything, it is a very nice
(but complex) piece of code I think. Look through the example
addressbook application, and the way the templates are held away from
the code that generates the rest of the html, how easy it would be to
add a few languages, etc... you will see!

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация