Welcome Guest, Not a member yet? Register   Sign In
Should I use _remap for this?
#1

[eluser]zyzzzz[/eluser]
I've been using CodeIgniter for about a week now, its the first framework I've used and must say that it definately makes things more managable.

Normally I would use GET for this, but seems it is disabled by default, and I want 'pretty' urls, I thought I would keep it that way.

On my website, there is a hierarchy in the 'browse' section that could possibly drill down quite deep. It would look something like this (forgive me for not drawing tree diagrams but it was too difficult lmao).

Browse -> [LANGUAGE NAME] -> [LANGUAGE SUBCATEGORY?] -> [CODE CATEGORY?] -> [PAGE NUMBER]

For example, any of these would be valid urls, and a view would need to be loaded.
/browse/
/browse/ruby/
/browse/asp-net/algorithms/10
/browse/c/c-plus-plus/2

Now, I've got my 'browse' controller saved, but I'm not really sure what to put it in. I would have been able to figure out the best way to use the _remap function (just a few switch statements perhaps? Although I would be pulling values out of the DB as opposed to hardcoding them), except some of the uri segments can be optional.
- The 'subcategory' is optional
- The 'code category' is optional
Basically those two are just filters for what is being display.

The problem is that on any given page, for example URI segment 3 could be the code category, or it could be a language subcategory.

The only way I can think of doing this is:
For each uri segment where we don't know what data is in it, load up two arrays of all possible values and loop through until we get a hit, then we know what it is.

An alternative would be to put the optional 'filters' at the end of the URL:
/browse/c/2/c-plus-plus/algorithms
/browse/ruby/ruby-on-rails/applications

But still in both those examples, URI segment 3 could be either a page number or a language subcategory.

Anyone have any good ideas as to how to go about this?
Thanks!
#2

[eluser]jedd[/eluser]
Hi James and welcome to the CI forums.

I'm beginning to think that having a URL design of verb/noun is quite limiting, or at least effort-increasing, when working with MVC (and probably when not, too).

Would you still have this conundrum if you had a noun/verb approach to your URL - where your controller was, of course, the noun, and you had things like browse as methods within your controller(s)?
#3

[eluser]zyzzzz[/eluser]
Using the information I posted, what would be the noun and what would be the verb?
Sorry but you didn't make much sense to me, but thanks for the quick reply.
#4

[eluser]zyzzzz[/eluser]
Ah I understand what you meant now.
The problem is, the programming languages, the programming sub-categories, and the code categories are all pulled dynamically out of the database.
#5

[eluser]Phil Sturgeon[/eluser]
Take a look at uri_to_assoc() in the URI Class section of the manual.

It works just like $_GET parameters but uses the CI slashed segments.
#6

[eluser]jedd[/eluser]
While I understand that data is pulled out of the database, I don't believe that should dictate your presentation (controller) logic.

Sub-category of languages? In one case you've listed C++ (which I would not class as a sub-category of C - if anything, given C can be compiled cleanly by a C++ compiler, it could be argued to be the other way - but in reality they are separate languages). In another instance you have 'algorithms' as a sub-category of a given language, whereas to me an algorithm is language-independent (as long as we're talking about one variety of language - eg. 3GL's). If algorithms are something you are likely to do something substantial with, make a controller called algorithm.

I suspect your ER mapping may be not fully drawn out .. would that be a fair conclusion?

Do you have any control over your schema or is that already set in stone?

I'd probably have a language (a noun (or naming word)) controller, and the first argument would be the thing you want to do (verbs are doing words, okay). In this case it'd be browse, but you may decide to do other things in the future. I'd avoid language sub-category, as this doesn't make much sense to me (but maybe I just don't have enough example data to understand your intent).

Optional arguments are always going to be messy - and I suspect are the root of your confusion here - so you might want to reconsider that approach and have a default third argument (a place-holder, say, to ensure the third argument is always present) or drop it entirely - you do say that 'code category' is optional, and the only thing I can see about what it might mean is that it can be a '2' or a '10'. Again I might not have enough information to understand your intent with this parameter.




Theme © iAndrew 2016 - Forum software by © MyBB