Welcome Guest, Not a member yet? Register   Sign In
how to implement dynamic "routes"?
#11

[eluser]Jake Grice[/eluser]
Why not use MOD_REWRITE for this?

For example, www.ilyt.org/support.html actually is www.ilyt.org/index.php?page=support

Quote:Mapping Example:
http://testserver/asd.html
maps to:
http://testserver/controller/function.ht...country=de

Code:
RewriteRule ^([^/]+)\.html$  /index.php/Functions/Search/$1/de [NC]

So if you had a controller called Functions (probably not the best name for a controller), you could simply call:

www.yoursite.com/myquery.html

Which would actually load:
www.yoursite.com/Functions/Search/myquery/de

(Where the search function might look similar to)
Code:
function Search($query, $country)


I don't see why this shouldn't work.
#12

[eluser]Jake Grice[/eluser]
Or
Code:
RewriteRule ^([^/]+)-([^/]+)\.html$  /index.php/Functions/Search/$1/$2 [NC]

And you called
www.yoursite.com/myquery-de.html

Then it would load
www.yoursite.com/Functions/Search/myquery/de
#13

[eluser]narkaT[/eluser]
[quote author="narkaT" date="1221189446"]but post values aren't "copyable", and creating such "aliases"
should be as easy as it could.

copy an URI and assign it to an alias.[/quote]
that's the mission Wink


The params that'll get passed per URI could look like this:
Quote:VON=1221602400&BIS=1225148400&RA=2&KA1=18&KA2=18&KA3=18&VA=0&ZA=0&DAUER=0,0&PREIS=0,0
or this:
Quote:ZIEL=PMI&VON=1221602400&BIS=1225148400&RA=2&KA1=18&KA2=18&KA3=18&VA=0&ZA=0&DAUER=0,0&PREIS=0,0
or even like this:
Quote:ZIEL[]=PMI&ZIEL;[]=PMA&VON=1221602400&BIS=1225148400&RA=2&KA1=18&KA2=18&KA3=18&VA=0&ZA=0&DAUER=0,0&PREIS=0,0

The future users of this application have to be able, to create such mappings
by just copying the uri they want to "map" into an "admin utility".
parsing and rewriting an htaccess-file will be a bit tricky, but the point is:
how will a htaccess perform with ~50 to 100 rewrite-rules in it?

an "automatically" genreated rewrite rule would probably look like this:
Code:
RewriteRule ^pmi\.html$  /index.php/Functions/Search?ZIEL=PMI&VON=1221602400&BIS=1225148400&RA=2&KA1=18&KA2=18&KA3=18&VA=0&ZA=0&DAUER=0,0&PREIS=0,0 [NC]



the annoying fact about my current "solution" is, that the connection to the database is made twice.
the pre_system-hook gets executed too early to use the CI base, so the DB objekt in
the hook is independent from the core... :roll:


I'm thinking of combining the htaccess and the database-cached-searches
into a more effective system.

thank you for all the ideas so far Smile

Greetings
Jan
#14

[eluser]Bramme[/eluser]
what are you using the pre hook for again? There's a big chance you'll be able to cut it out of your code.
#15

[eluser]narkaT[/eluser]
I don't plan to use it again, the post is a bit "bad-structured" Wink

just tried to explain why the database connection is made twice.

Greetings
Jan
#16

[eluser]drewbee[/eluser]
Like we were suggesting earlier, do something like this:

Create a form along with a search id (note: search_id should be within the valid CI allowed_characters).

This form accepts the values of search_id, and the search query string.

From the form, insert search_id, and search_query_string into the database.

So now we have as an example in our table:

Code:
search_id (varchar) | search_query_string (text)
custom_search_1 | VON=1221602400&BIS=1225148400&RA=2&KA1=18&KA2=18&KA3=18&VA=0&ZA=0&DAUER=0,0&PREIS=0,0

So the user can go to
http://www.example.com/controller/method...m_search_1 and with a simple database query pull in search_query_string belonging to 'custom_search_1' as passed to method of controller.

No hooks, no hacks. I feel you are trying to make this more complex then what it needs to be. Each user can create there own mapping with this as well.

This is how I would do it, plus you get to maintain CI's security of the character requirement in the URI.

I apologize if I am not understanding your requirements better, or if I can better explain this let me know!
#17

[eluser]narkaT[/eluser]
that's what I'm planing to do Wink

the requirements are basically:
1) every search/URI is mapable to any alias
examples:
alias.html -> /controller/search/<search_id>
alias2.html -> /anothercontroller/list/123

2) easy creation of mappings for the "maintainer" of the site (the maintainer has minimal/none IT-knowledge)


I'll combine the database and mod_rewrite ideas Smile

sometimes I'm definitely thinking in too complex ways Big Grin

Greetings
Jan
#18

[eluser]Bramme[/eluser]
For the custom aliases you'll probably want to use a _remap function.

In your routes file, add something like
Code:
$route['(.*)'] = '/alias/$1';

And then in your alias controller you can use a _remap function that searches the database for aliases, if found, redirect in the right direction (if you don't want the url to change, you'll have to call logic in the remap function I guess). If it's not found, Send a 404 header and show the 404 page.
#19

[eluser]narkaT[/eluser]
but the "(.*)"-route applies to "existing" controller/method combination too?

I would like to be able to still use the normal URI scheme for caling an existing
controller/method Wink
I would have to call the method "manually" in the _remap method?

Greetings
Jan
#20

[eluser]Bramme[/eluser]
True, you would have to set up routes to your other controllers first. Or you could extend the router class and redirect to the alias controller before it shows the standard 404 page.




Theme © iAndrew 2016 - Forum software by © MyBB