Welcome Guest, Not a member yet? Register   Sign In
regarding URLs / Titles
#5

OK, first, it looks like your detail method in the Inventory controller calls your Inventory_model's get_record() method, but the controller doesn't grab the number from the URL, so I'm guessing the model is doing that (in a perfect world the model wouldn't do that, but it looks like your model may be doing that in get_records_or_make() and get_archived(), as well).

Since you don't have a field in the database that's already populated with the information you want to use in the URL, you have to decide whether you want to specify a way to map the URL to fields in the database, or create a new column to use to lookup the correct entry in the database. For example, if you go to "/inventory/detail/1959-rolls-royce-phantom", you could do something like this:

PHP Code:
$lookup $this->uri->segment(3);
$lookupValues explode('-'$lookup);
// Now $lookupValues is array('1959', 'rolls', 'royce', 'phantom') 

The problem should be readily apparent, as you have the year (1959), but the make, 'rolls-royce' (I'm assuming), is split across two entries in the array, while other makes would be a single entry, and still others might be more, and the model would have the same issue.

One common approach to solving this problem is to create a "slug" (what I previously referred to as a title) from the fields and insert that as a new column in the database. So, your new column would have a value of '1959-rolls-royce-phantom' for that particular row in the database (you could write a script to populate this column after creating it in the database, using the production_year, make, and model to build the "slug"; the url_title() function in CI's URL helper tends to be very useful for something like that).

Another alternative is to change the URL format that you would like to use. For example, you could use "/inventory/detail/1959/rolls-royce/phantom". Then you could do something like this:

PHP Code:
$year $this->uri->segment(3);
$make $this->uri->segment(4);
$model $this->uri->segment(5); 

or even:
PHP Code:
public function detail($year$make$model

It looks like your model's get_makes() method might already do something to deal with looking up the make from the URL, but the make() method of the controller uses urldecode($this->uri->segment(3)), which tells me the model's method may not be SEO-friendly. So, you might still need a column (or two) to hold SEO-friendly versions of the make (and probably model) names, or a lookup table (or two) to map the SEO-friendly names to the names used in the existing make and model columns.
Reply


Messages In This Thread
regarding URLs / Titles - by lc317 - 10-28-2015, 10:59 AM
RE: regarding URLs / Titles - by mwhitney - 10-28-2015, 12:57 PM
RE: regarding URLs / Titles - by lc317 - 10-28-2015, 04:01 PM
RE: regarding URLs / Titles - by lc317 - 10-29-2015, 11:26 AM
RE: regarding URLs / Titles - by mwhitney - 10-29-2015, 12:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB