Is possible to change pagination url names in cakephp? - cakephp

Is possible to change pagination url names in cakephp?
For example:
example.com/tests/act/page:2/sort:title/direction:desc
to:
example.com/tests/act/pg:2/link:title/orderby:-date
Thank you all. But I am beginner in cakephp and pleased to see an example.
I read the documentation. but there is nothing about things I want.
Maybe I can translate those parameters and give to the Paginator class. but how?

Yes. Use routing. http://book.cakephp.org/2.0/en/development/routing.html
Just create a rewrite rule for it.

Pagination Works with named parameters, and there is not a simple way to rename them. You will need to modify the PaginatorComponent and PaginatorHelper to modify the parameters of the pagination.

Related

Wagtail - how to put two fields in one row in admin form?

I would like to put two fields next to each other. I didn't find any instructions in the wagtail documentation so I think it's more tricky or not possible in the current wagtail solution. I suppose that the only way to achieve it is the override edit form the HTML file, right?
I would like to have something like this:
You probably need the FieldRowPanel. Reference: https://docs.wagtail.io/en/latest/reference/pages/panels.html#fieldrowpanel

CakePHP show variable value

I'm using CakePHP (v3.0) and I want to show on screen the variable value.
I have tried to use print_r() function, but not always runs..
Whats would be the best option?
CakePHP comes with pr() function you can use that
Documentation link
I always use cake's debug() function, but you should consider using DebugKit for debugging your app.
DebugKit

How to use default.ctp in cakephp

I just finished the "15 min Blog Post tutorial" included in the documentation for cakephp. I was asked for another tutorial to change the layout for first tutorial.
However, I am fairly new to MVC programming/Cakephp and I have no real clue how to do so. Well, I know I need "default.ctp" placed in app/views/layouts/ and I presume I need to include
to include my data? . . .
I am really at a loss of what to do. I set up my default.ctp as I mentioned above, but when I go to localhost:9999/posts the layout is still the same. I guess I need to include a stylesheet (and if so, where?)
I guess if someone can point me in the right direction to a beginner's guide to layout styling or how to use it I would greatly appreciate any help.
I would advice you to read the following from the cookbook: Layouts and CSS. Then copy the layout from /cake/libs/view/layouts/ to /app/views/layouts/ and modify it to your needs. After that create you stylesheet (or modify existing one) in /app/webroot/css/ and include it in your layout.
Create in app/View/Layout a file named "my_posts_layout.ctp"
In your PostController set $this->layout = 'my_posts_layout';
This way you should view the content defined on my_posts_layout.ctp.
Lack of stylesheets has no impact here.
How MVC works in CakePHP:
The router dispatches an incoming request to an appropriate Contoller.
The appropriate Controller function executes (no output, just fetching data, setting up variables).
The appropriate view is rendered. In fact, the output of the view is just contained in $content_for_layout.
What you really get back in the browser is in the layout. Therefore you can put your view's output into the layout by echo $content_for_layout in default.ctp. (Of course you can also have different layouts.) In addition, the layout can be enhanced with elements.
I really recomend the CakePHP CookBook, easily found from the CakePHP homepage. Modifying default.ctp should edit your applications layout.
A more specific question (eg. code samples of your default.ctp, expected results etc) might help people provide a better answer than mine.

cakephp and get requests

How does cakephp handle a get request? For instance, how would it handle a request like this...
http://us.mc01g.mail.yahoo.com/mc/welcome?.gx=1&.rand=9553121_pg=showFolder&fid=Inbox&order=down&tt=1732&pSize=20&.rand=425311406&.jsrand=3
Would "mc" be the controller and "welcome" be the action?
How is the rest of the information handled?
Also note that you could use named parameters as of Cake 1.2. Named parameters are in key:value order, so the url http://somesite.com/controller/action/key1:value1/key2:value2 would give a a $this->params['named'] array( 'key1' => 'value1', 'key2' => 'value2' ) from within any controller.
If you use a CNN.com style GET request (http://www.cnn.com/2009/SHOWBIZ/books/04/27/ayn.rand.atlas.shrugged/index.html), the parameters are in order of appearance (2009, SHOWBIZ, books, etc.) in the $this->params['pass'] array, indexed starting at 0.
I strongly recommend named paramters, as you can later add features by passing get params, without having to worry about the order. I believe you can also change the named parameter separation key (by default, it's ':').
So it's a slightly different paradigm than the "traditional" GET parameters (page.php?key1=value1&key2=value2). However, you could easily add some logic in the application to automatically parse traditional parameters into an array by tying into how the application parses requests.
CakePHP uses routes to determine this. By default, the routes work as you described. The remainder after the '?' is the querystring and it can be found in $this->params['url'] in the controller, parsed into an associative array.
Since I found this while searching for it, even though it's a little old.
$this->params['url']
holds GET information.
I have tested but it does work. The page in the Cakephp book for it is this link under the 'url' section. It even gives an example very similar to the one in the original question here. This also works in CakePHP 1.3 which is what I'm running.
It doesn't really use the get in the typical since.
if it was passed that long crazy string, nothing would happen. It expects data in this format: site.com/controller/action/var1/var2/var....
Can someone clarify the correct answer? It appears to me that spoulson's and SeanDowney's statements are contradicting each other?
Would someone be able to use the newest version of CakePHP and get the following url to work:
http://www.domain.com/index.php/oauth/authorize?oauth_version=1.0&oauth_nonce=c255c8fdd41bd3096e0c3bf0172b7b5a&oauth_timestamp=1249169700&oauth_consumer_key=8a001709e6552888230f88013f23d5d004a7445d0&oauth_signature_method=HMAC-SHA1&oauth_signature=0bj5O1M67vCuvpbkXsh7CqMOzD0%3D
oauth being the controller and authorize being a method AS WELL as it being able to accept the GET request at the end?

Why doesnt paginator remember my custom parameters when I go to page 2?

When using the paginator helper in cakephp views, it doesnt remember parts of the url that are custom for my useage.
For example:
http://example.org/users/index/moderators/page:2/sort:name/dir:asc
here moderators is a parameter that helps me filter by that type. But pressing a paginator link will not include this link.
The secret is adding this line to your view:
$paginator->options(array('url'=>$this->passedArgs));
(I created this question and answer because it is a much asked question and I keep having to dig out the answer since i cant remember it.)
To add to Alexander Morland's answer above, it's worth remembering that the syntax has changed in CakePHP 1.3 and is now:
$this->Paginator->options(array('url' => $this->passedArgs));
This is described further in the pagination in views section of the CakePHP book.
$this->passedArgs is the preferred way to do this from the view.
You saved me! This helped me a lot, Thanks.
I needed a way to pass the parameters I originally sent via post ($this->data) to the paging component, so my custom query would continue to use them.
Here is what I did:
on my view I put
$paginator->options(array('url'=>$this->data['Transaction']));
before the $paginator->prev('<< Previous ' stuff.
Doing this made the next link on the paginator like "
.../page:1/start_date:2000-01-01%2000:00:00/end_date:3000-01-01%2023:59:59/payments_recieved:1"
Then on my controller I just had to get the parameters and put them in the $this->data so my function would continue as usual:
foreach($this->params['named'] as $k=>$v)
{
/*
* set data as is normally expected
*/
$this->data['Transaction'][$k] = $v;
}
And that's it. Paging works with my custom query. :)
The options here are a good lead ... You can also check for more info on cakePHP pagination at cakephp.org/view/166/Pagination-in-Views
With that param 'url' you can only put your preferred string before the string pagination in url..
if I use this tecnique:
$urlpagin = '?my_get1=1&my_get2=2';
$paginator->options = array('url'=>$urlpagin);
I only obtain:
url/controller/action/?my_get1=1&my_get2=2/sort:.../...
and Cake lost my get params
Have you an alternative tecnique?

Resources