• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with uri segments

#1
[eluser]Atharva[/eluser]
Hi,

My problem with URI segments and may occur if user is destructive minded ( Confusedmirk: )

The initial link would be like
Code:
http://domain.com/index.php/controller/index/
When user clicks on a sorting link
Code:
http://domain.com/index.php/controller/index/resTakeOut/DESC/1/0
Where index is a function and rest are the parameters.
So the current uri segments are
1=>controller
2=>index
3=>resTakeOut
4=>DESC
5=>1
6=>0
So the problem I identify during destructive testing is that if I deletes a uri segment then it gives me a db error
eg: http://domain.com/index.php/controller/i...keOut//1/0[/code]
will give me a db error like
Code:
SELECT SQL_CALC_FOUND_ROWS * FROM cs_table where cId= 1 order by(resTakeOut) 1 LIMIT 0,10
This is due to the fact that CI will not identify the 'empty' uri segment between the two slashes '//'. So the new uri segments are
1=>controller
2=>index
3=>resTakeOut
4=>1
5=>0

So as you can see it takes uri segment 4 for order by (desc/asc) clause in the query which now will be '1' which is invalid for sql query.

So the whole problem lies in the fact that CI don't recognizes the empty uri between //. I have taken the default vales for the function index but it will not help since the uri segment 5 will be treated as segment 4. So I am wondering if there is any solution for this? I had a look at uri class but not sure how I can overcome this problem.

I appreciate your help. Thanks.

#2
[eluser]Dam1an[/eluser]
You could use routes for this
Make sure to check that segment 3 is a string, that segment 4 is either ASC or DESC, and that segments 5 and 6 are numeric

If I have some time later (and what I said above wasn;t very clear) i'll come up with an example

#3
[eluser]Atharva[/eluser]
[quote author="Dam1an" date="1240924454"]You could use routes for this
Make sure to check that segment 3 is a string, that segment 4 is either ASC or DESC, and that segments 5 and 6 are numeric

If I have some time later (and what I said above wasn;t very clear) i'll come up with an example[/quote]

Thanks. But I am not sure whether routing will help. Can you show any example for it? Also, my site is quite big so I was wondering if there is any another simpler solution for this.

#4
[eluser]Dam1an[/eluser]
A simpler solution would be to use a javascript table sorter, which would also save having to do another database query each time
(Although I've never used one, so can't really recommend it, but something to look into)

#5
[eluser]Dam1an[/eluser]
As promised, here's some quick routes I threw together (not tested)
Code:
// Everything is specified
$route['controller/index/(:any)/(ASC|DESC)/(:num)/(:num)'] = "controller/index/$1/$2/$3/$4";
// Default to ASC
$route['controller/index/(:any)/(:num)/(:num)'] = "controller/index/$1/ASC/$3/$4";
// Default values for whatever the 0 and 1 is at the end
$route['controller/index/(:any)/(ASC|DESC)'] = "controller/index/$1/$2/0/1";

Make sense?

#6
[eluser]Atharva[/eluser]
Thanks Dam. But I got it working some another way. Thanks for your help.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.