Home
About
Testimonials
Demos
Download
Documentation
Forum
Development
Forum
Help
Search
Chatroom
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
Mar. 14, 2010, 03:37:59 AM
52782
Posts in
11730
Topics by
7940
Members
Latest Member:
Wright096
News
: New to PRADO? The
PRADO blog tutorial
is a good start point.
The PRADO Community
»
Prado v3.x
»
General Discussion
»
friendly-url for dummies
« previous
next »
Pages:
[
1
]
2
3
Author
Topic: friendly-url for dummies (Read 7781 times)
rabol
Senior Member
Karma: 10
Offline
Posts: 254
friendly-url for dummies
«
on:
Nov. 07, 2008, 10:22:33 PM »
Hi
I have searched the forum and read the wiki, but for some reasons I can't make Pradp working with friendly-url.
What I want is very simple: index.php?page=test should become /test or index.php?page=test.test should become /test/test or index.php?page=test.test&id=20 should become /test/test/id/20 etc.
I'm using Apache and mod_rewrite is working... at least for other web apps
Br
Steen
Logged
Creator of Prado Portal -
www.pradoportal.dk
Carl
PRADO v3.x Developer
Platinum Member
Karma: 19
Offline
Posts: 529
Re: friendly-url for dummies
«
Reply #1 on:
Nov. 07, 2008, 11:12:28 PM »
Quick (most basic) example in application.xml
Code:
<!-- connect your request module to an url manager -->
<module id="Request" class="THttpRequest" UrlManager="friendly-url" />
<!-- set up your url manager module with url nodes as children -->
<module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true">
<url ServiceParameter="test" pattern="test" ServiceID="page" />
</module>
ServiceParameter = your page class name
Pattern = your friendly name
ServiceID = page service id
Remember to also set the mod rewrite lines in .htaccess:
Code:
Order allow,deny
Allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^page,(.+)$ index.php/page,$1
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteBase is your URI, e.g if the index file is placed at
http://example.org/index.php
, RewriteBase is /. If your site is placed at
http://example.org/site/index.php
, your RewriteBase is /site/
Logged
Kamikaze Media
|
Filmfront
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #2 on:
Nov. 08, 2008, 05:51:32 PM »
Please let us know, if you think there should be more information in the wiki article on friendly URLs. (
http://www.pradosoft.com/wiki/index.php/Friendly_URLs_(3.1.1_and_above)
)
Logged
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #3 on:
Nov. 08, 2008, 07:46:41 PM »
Quote from: mikl on Nov. 08, 2008, 05:51:32 PM
Please let us know, if you think there should be more information in the wiki article on friendly URLs. (
http://www.pradosoft.com/wiki/index.php/Friendly_URLs_(3.1.1_and_above)
)
Yes, please more information
I for one did read it and could not make it work, I'll try the hints from Carl, and let you know
Logged
Creator of Prado Portal -
www.pradoportal.dk
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #4 on:
Nov. 08, 2008, 08:07:56 PM »
Quote from: Carl on Nov. 07, 2008, 11:12:28 PM
Quick (most basic) example in application.xml
Code:
<!-- connect your request module to an url manager -->
<module id="Request" class="THttpRequest" UrlManager="friendly-url" />
<!-- set up your url manager module with url nodes as children -->
<module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true">
<url ServiceParameter="test" pattern="test" ServiceID="page" />
</module>
ServiceParameter = your page class name
Pattern = your friendly name
ServiceID = page service id
Remember to also set the mod rewrite lines in .htaccess:
Code:
Order allow,deny
Allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^page,(.+)$ index.php/page,$1
# we skip all files with .something
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule .* - [L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteBase is your URI, e.g if the index file is placed at
http://example.org/index.php
, RewriteBase is /. If your site is placed at
http://example.org/site/index.php
, your RewriteBase is /site/
Well, some of it works, but it will require that I add a lot of <url..> lines.
Maybe I'll try to explain myself a little better
I need a combination of semi-static and dynamic rewrite.
In my portal I have a Directory 'System' and 'Admin' in a sub folder of /Pages, and pages in these 2 folders is normally called like this: index.php?page=System.XXX (where XXX is the name e.g Login) I would like that it becomes:
http://example.com/System/Login
or
http://example.com/System/OpenIdLogin
, but without adding a line in application.xml for each page.
I would like that e.g
http://example.com/index.php?page=contact
look like this
http://example.com/contact
- Basically I would like that all pages in the /protected/Pages or /protected/Pages/sub/* or /protected/Pages/sub/sub/*
I hope that you can see my point
Thanks
Br
Steen
«
Last Edit: Nov. 08, 2008, 08:18:35 PM by rabol
»
Logged
Creator of Prado Portal -
www.pradoportal.dk
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #5 on:
Nov. 08, 2008, 09:15:15 PM »
In my case I have found a solution that works for now...
I have created a function that build a XML file with all the possible pages, and then added ConfigFile="Application.runtime.urlmap" in application.xml
br
Steen
Logged
Creator of Prado Portal -
www.pradoportal.dk
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #6 on:
Nov. 08, 2008, 11:21:52 PM »
Would your problem be solved, if we enhanced TUrlMapping to also accept mappings of this form?
Code:
<module id="friendly-url" class="System.Web.TUrlMapping" EnableCustomUrl="true" UrlPrefix="/myapp">
<url ServiceParameter="System.Articles"
pattern="articles/{year}/{month}/{day}"
parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
<url ServiceParameter="System.*" pattern="System" />
</module>
$this
->
constructUrl
(
'System.Articles'
,array(
'year'
=>
2008
,
'month'
=>
10
,
'day'
=>
15
);
Creates
/myapp/articles/2008/10/15
$this
->
constructUrl
(
'System.Articles'
);
Creates
/myapp/System/Articles
$this
->
constructUrl
(
'System.UserEdit'
,array(
'id'
=>
15
));
Creates
/myapp/System/UserEdit/id/15
$this
->
constructUrl
(
'System.Login'
);
Creates
/myapp/System/Login
Logged
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #7 on:
Nov. 09, 2008, 06:47:51 AM »
Quote from: mikl on Nov. 08, 2008, 11:21:52 PM
Would your problem be solved, if we enhanced TUrlMapping to also accept mappings of this form?
Well... it would make the urlmapping file smaller as I 'only' have to have one <url..> pr. subdirectory.
(Please have in mind that sub directories are created on a pr. user/site base and is 'unlimited' as with the index.php?page=sub.sub.sub.sub.sub.page)
How would you suggestion handle this index.php?page=NewsPaper.Section.Sport.Golf.Tournamet.EGA.VolvoMasters.Info&Year=2008&GetWhat=winner ?
It is actually possible in Prado to have pages like the above
Have in mind that everything after NewsPaper. could be more or less dynamic created.
Logged
Creator of Prado Portal -
www.pradoportal.dk
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #8 on:
Nov. 09, 2008, 02:32:53 PM »
Hmm, i think, i don't get the point of having hundreds (or even thousands) of page files in subdirs as you described it. Wouldn't it be better to have only one page file that handles all the categories like page=NewsPaper§ion=Sport&type=Golf&subtype=Tournament... ? Otherwhise i don't really see, what you win with a framework over simply using static html files in a static directory structure.
The other point is: You want an URL like this, i guess:
/myapp/NewsPaper/Section/Sport/Golf/Tournament/EGA/VolvoMasters/Info/Year/2008/GetWhat/winner
I can't think of a way to automatically decide, what part of that URL should be part of the page path and what should be a parameter.
Logged
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #9 on:
Nov. 09, 2008, 03:28:43 PM »
Quote from: mikl on Nov. 09, 2008, 02:32:53 PM
Hmm, i think, i don't get the point of having hundreds (or even thousands) of page files in subdirs as you described it. Wouldn't it be better to have only one page file that handles all the categories like
page=NewsPaper§ion=Sport&type=Golf&subtype=Tournament... ?
The world is dynamic
I don't say that the above is the perfect example, but can you imagine how big a page you should have to handle all the different parameters if your suggestion was the only one?
Quote
Otherwhise i don't really see, what you win with a framework over simply using static html files in a static directory structure.
well... 95% of all the web pages could be static HTML, so why do you even develop a framework ?
Quote
The other point is: You want an URL like this, i guess:
/myapp/NewsPaper/Section/Sport/Golf/Tournament/EGA/VolvoMasters/Info/Year/2008/GetWhat/winner
Correct, that is what I would love Prado to be able to handle
Quote
I can't think of a way to automatically decide, what part of that URL should be part of the page path and what should be a parameter.
How do you decide what part NewsPaper/Section/Sport is the page and what part is the parameter
My point is that Prado have a - IMHO - very nice feature where you can have pages in a subdir where NewsPaper.Section.Sport.Home is a page with the physical location of /pages/NewsPaper/Section/Sport/Home.page, and if you allow unlimited subdirs, then urlmapping should be possible.
I do agree that It might not be a 'problem' that should be solved by the framework - And if you -as a core developer - say that the framework don't can/will support REAL url mapping, I have to either live with that og find some kind of solution. CI, Kohana, CakePHP/ can handle urlmappings so I just thought that Prado could too.
Logged
Creator of Prado Portal -
www.pradoportal.dk
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #10 on:
Nov. 09, 2008, 04:11:38 PM »
Quote from: rabol on Nov. 09, 2008, 03:28:43 PM
Quote
I can't think of a way to automatically decide, what part of that URL should be part of the page path and what should be a parameter.
How do you decide what part NewsPaper/Section/Sport is the page and what part is the parameter
That was exactly my question for you
If you can't even tell - how should some code do? Any rule enhancement a) needs a unambigous logic on how URLs are created and b) it's implementation should not be to "expensive" in the sense of code execution time.
The solution i described above could be added to TUrlMapping without much effort. And the logic here is quite simple:
Whenever we have a ServiceParameter like "System.*" and the according pattern is "patternxy", URLs to pages in the System path would always look like this:
/myapp/patternxy/PAGE/parameter1/value1/parameter2/value2
Where PAGE could be any page in the System.* path. It would even be possible to define finer grained rules for some specific pages in System.* as long as these rules preceed the catch-all System.* rule. See the example above.
Logged
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #11 on:
Nov. 09, 2008, 05:30:32 PM »
Quote from: mikl on Nov. 09, 2008, 04:11:38 PM
The solution i described above could be added to TUrlMapping without much effort. And the logic here is quite simple:
Whenever we have a ServiceParameter like "System.*" and the according pattern is "patternxy", URLs to pages in the System path would always look like this:
/myapp/patternxy/PAGE/parameter1/value1/parameter2/value2
Where PAGE could be any page in the System.* path. It would even be possible to define finer grained rules for some specific pages in System.* as long as these rules preceed the catch-all System.* rule. See the example above.
Yes, and this - as I said - would reduce the number of lines in the urlmap.xml file that I add as parameter to TUrlMapping, so that will 'solve' a big part of the url mapping 'problem' that I have.
Br
Steen
Logged
Creator of Prado Portal -
www.pradoportal.dk
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #12 on:
Nov. 10, 2008, 10:42:41 AM »
I'd like to hear more opinions before we specify how this enhancement should work. I also thought about some "catch-all" parameters like this:
Code:
<url ServiceParameter="Admin.*" pattern="admin/*/date/{year}/{month}/{day}"
parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
<url ServiceParameter="Admin.*" pattern="admin" />
That means, that
every
page under Admin would accept a date parameter in the specified format. The second line makes this parameter optional.
Logged
rabol
Senior Member
Karma: 10
Offline
Posts: 254
Re: friendly-url for dummies
«
Reply #13 on:
Nov. 10, 2008, 08:49:05 PM »
Quote from: mikl on Nov. 10, 2008, 10:42:41 AM
I'd like to hear more opinions before we specify how this enhancement should work. I also thought about some "catch-all" parameters like this:
Code:
<url ServiceParameter="Admin.*" pattern="admin/*/date/{year}/{month}/{day}"
parameters.year="\d{4}" parameters.month="\d{2}" parameters.day="\d+" />
<url ServiceParameter="Admin.*" pattern="admin" />
That means, that
every
page under Admin would accept a date parameter in the specified format. The second line makes this parameter optional.
Sounds perfect to me
Thanks!
Logged
Creator of Prado Portal -
www.pradoportal.dk
mikl
PRADO v3.x Developer
Platinum Member
Karma: 63
Offline
Posts: 951
Re: friendly-url for dummies
«
Reply #14 on:
Nov. 24, 2008, 05:28:47 PM »
Ok, i've done a basic implementation in SVN. We now can have these new pattern formats:
Code:
<url ServiceParameter="Subfolder.admin.*" pattern="subfolder/{*}" />
<url ServiceParameter="*" pattern="{*}/{anything}" parameters.anything=".+" />
<url ServiceParameter="*" pattern="{*}" />
{*} will get replaced with the serviceParameter (a.k.a. the page name for TPageService).
First line creates friendly URLs for any page in Subfolder.admin.*. This is non-recursive now, which means that every subfolder needs it's own rule.
Second line creates a catch-all pattern for all pages in the pages folder with a common parameter "anything" that's shared by all pages there. And the last line is a catch-all for all pages without any parameter.
I've not implemented anything for automatic parameter encoding yet. I'm not sure yet, how to proceed here.
Maybe someone could test the new feature and see if everything still works with old url mappings.
Logged
Pages:
[
1
]
2
3
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> Announcements
=> Prado-powered Applications
=> Prado International
===> Chinese
===> Dutch
===> French
===> German
===> Indonesian
===> Italian
===> Japanese
===> Polish
===> Portuguese
===> Russian
===> Spanish
=> Job Opportunities
-----------------------------
Prado v3.x
-----------------------------
=> General Discussion
===> Active Controls (Ajax)
===> Database
===> JavaScript
===> General PHP Topics
===> PRADO Extension
=> Installation and Setup
=> Feature Requests
=> Bug Reports
=> Tips, Snippets and Tutorials
===> Screencasts
=> Component Repository
-----------------------------
Prado-related Projects
-----------------------------
=> PRADO Community Project
=> PetShop Project
=> Entity framework
=> IDE/Editor for Prado
-----------------------------
Prado v2.x
-----------------------------
=> General Discussion
===> Installation and Setup
===> Active Controls (Ajax)
===> Feature Requests
=> Bug Reports
=> Tips, Snippets and Tutorials
=> Component Repository
-----------------------------
Beyond Prado
-----------------------------
=> Miscellaneous
Terms of Service
|
Contact Us
Copyright © 2006-2007 by the PRADO Group.
Powered by SMF 1.1.11
|
SMF © 2006, Simple Machines LLC