1

Why does CakePHP producing those URLs

<server>/Reporting/OnlineBanking/index/page:1 

instead of

<server>/Reporting/OnlineBanking/index?page=1 

There are alot of trouble with this using relative paths out of JavaScript for example.

And is there an option to change it?

5
  • Updated, hope that help, if dont please let me know. Commented Jul 15, 2013 at 14:09
  • You right with that cutting after slash. I updated with how I enter session_details. Also tried with "postLink" form the FormHelper but the session_id parameter also displayed in the URL. What confusing me like nothing else. Commented Jul 16, 2013 at 6:18
  • Confusing because of the format. Normally the parameters are in the url like that "session_details/session_id=XXXXXX&session_id_2=YYYYYY." If they would be like that i wouldnt have that problem with the relative path out of Javascript Commented Jul 16, 2013 at 9:12
  • Dude! thats it! :D The Paginator using "named"-Parameters as default too, that makes me get into trouble because I can never fix this problem without changing the paramType of the Pager. You really helped me alot. Write that as an answer so i cant mark it as correct. Commented Jul 16, 2013 at 10:50
  • Sorry for that unclear question before, its hard to write a good question without knowing where the problem could come from. Please write your answer out of the last comment to an answer. Commented Jul 16, 2013 at 11:05

1 Answer 1

1

Pagination with get parameters

By default, all parameters in CakePHP are named parameters (url fragments like /foo:bar/). This also applies, by default, to pagination arguments.

To use get arguments for pagination params - you can do that by setting appropriate config:

public $paginate = array( 'paramType' => 'querystring' ); 

This will generate urls of the form:

/the/url?page=1&limit=10 

Instead of:

/the/url/page:1/limit:10 

Specifying urls as string is extremely fragile

Previously you mentioned using urls like get_backend_requests in javascript.

You will still find problems if you do that even using get arguments of pagination. That's because even for the "same" url, the result can be different:

/the/url => /the/get_backend_requests /the/url/ => /the/url/get_backend_requests 

Instead - specify urls in javascript as absolute urls:

$.ajax({ type: 'POST', url: "/xyz/get_backend_requests", ... 

If you're app is sometimes (or always) installed in a subfolder, you can account for that with a simple function:

e.g. in your html/layout put:

<html> ... <script> function url(url) { return <?php $base = rtrim(Router::url('/'), '/'); if ($base) { echo "'$base' + "; } ?>url; } </script> 

Which will output:

<html> ... <script> function url(url) { return '/subfolder' + url; } </script> $.ajax({ type: 'POST', url: url("/xyz/get_backend_requests"), // becomes the string "/subfolder/xyz/get_backend_requests" ... 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.