I have a list of categories which displays the list of items under it.
Thus:
routes have:
Router::connect('/category/:slug', array('controller' => 'Product',
'action'=>'catview', 'slug'=> '[0-9a-zA-Z]+'));
Router::connect('/category/:slug/:page', array('controller' => 'Product',
'action'=>'catview','slug'=> '[0-9a-zA-Z]+','page'=>'[0-9]+'));
and
when I do this in results page, it just doesn't work:
<?php
$slug = $this->params['slug'];
$this->Paginator->options(array('url'=> array('controller' => 'Product',
'action'=>'catview','slug'=> $slug)));
echo $this->Paginator->prev('<< Show me previous', array('class'=>'prev'))
. $this->Paginator->next('Show me more >>', array('class'=>'next')); ?>
It does not change the results, it shows the same result as it does on page 1.
Any ideas where I am going wrong?
Thanks to AD7six for the reference.
My controller needs to have :
$this->paginate = array(
//other stuff here
'paramType' => 'querystring'
);
Followed by:
$this->Paginator->options(array('url'=> array('controller' => 'Product',
'action'=>'catview','slug'=> $slug),
'convertKeys' => array('page')));
in the view file
Related
Using this code:
$sitemap = 4;
$link = $this->Html->link( $sitemap . '.xml', null,
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
I expect to get a link that looks like this:
http://www.domain.com/vreb_listings/vreb_listing_feeds/view/4.xml
Instead, I get this:
/admin/vreb_listings/vreb_listing_feeds/4.xml
What gives? The action => view is having no effect, as view doesn't show up in the url, and the admin => false isn't working either, as admin does show up. This code is in the admin area.
I haven't even looked up how to include the full domain path in the url. Also, I want the title text to be the same as the url.
According to docs, the second parameter is the url one, so in your code it should be
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
(remove the null second parameter)
Oh, and for title text, that is the third parameter, so
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false),
array('title' => $sitemap.'.xml'));
should do the trick
I'm using CakePHP v2.42 & would like to have SEO friendly URL in page pagination.
My current pagination is like
http://www.website.com/ubs/page/page:2
What to do to change to
http://www.website.com/ubs/page/2
My Controller is
<?php
class UbsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->paginate = array(
'limit' => 100,
);
$ubs = $this->paginate();
$this->set('ubs', $ubs);
}}
My Router is
Router::connect('/ubs', array('controller' => 'ubs', 'action' => 'index'));
Router::connect('/ubs/page/*', array('controller' => 'ubs', 'action' => 'index'));
EDIT - ADD MORE QUESTION
Answer by #kicaj is perfectly correct for the Router & Controller. However, the navigation link only display correctly on the first page.
In the first page navigation link show like this which is correct
http://www.website.com/ubs/
http://www.website.com/ubs/page/2/
http://www.website.com/ubs/page/3/
But navigation link show like this in second/third page page
http://www.website.com/ubs/index/2/
http://www.website.com/ubs/index/2/page:3/
I guess need to edit index.ctp file but not sure what to do.
My current navigation link in index.ctp show like this
$paginator = $this->Paginator;
$paginator->prev("« Prev");
$paginator->numbers(array('modulus' => 200, 'separator' => ' '));
$paginator->next("Next »");
What to change to correct this
Try this:
Router::connect('/ubs/page/:page', array(
'controller' => 'ubs',
'action' => 'index'
), array(
'pass' => array(
'page'
),
'page' => '[\d]+'
));
and in index action in ubs controller add code bellow:
public function index($page = 1) {
// ...
$this->request->params['named']['page'] = $page;
// ...
}
In your Paginator Helper you can choose the right friendly url you want with setting some options
url The URL of the paginating action. ‘url’ has a few sub options as well:
sort The key that the records are sorted by.
direction The direction of the sorting. Defaults to ‘ASC’.
page The page number to display.
There here an example .
$this->Paginator->options(array(
'url' => array(
'sort' => 'email', 'direction' => 'desc', 'page' => 6,
'lang' => 'en'
)
));
the source : Modifying the options PaginatorHelper uses
What im trying to do here is maintain the variable 42 all throughout all pagination urls. I want my url to change from this
/exams/take/42/page:2
to this
/exams/take/42/items/2
Again,the number 42 is the variable..and the number 2 is the page number..Thanks.
UPDATE :
routes.php
Router::connect('/examinations/take/:id/page/:page',
array('controller' => 'examinations', 'action' => 'take'),
array(
'pass' => array('id', 'page'),
'id' => '[0-9]+',
'page' => '[0-9]+'
)
);
in the view/take
$this->Paginator->options(array('url' => $this->passedArgs));
AppController.php
public function beforeFilter(){
if (isset($this->request->params['page'])) {
$this->request->params['named']['page'] = $this->request->params['page'];
}
}
ive tried this ..but the generated url is the same,/examinations/take/42/page:2 ,when i click the next and prev links..
You've to define custom routes:
http://book.cakephp.org/2.0/en/development/routing.html
Example as below:
Router::connect(
'/exams/take/:id/items/:number',
array('controller' => 'exams', 'action' => 'take'),
array('pass' => array('id', 'number'))
);
Also you can get more information from below url try this:
http://www.sakic.net/blog/changing-cakephp-pagination-urls
yes you can do it with the use of custom routing. for more undrestanding you can see cakephp manual to manage custom routing in pagination
http://book.cakephp.org/2.0/en/development/routing.html
below will be your
e.g.
And by adding this route:
Router::connect('/:id/page/:page',
array('controller' => 'examinations', 'action' => 'take'),
array(
'pass' => array('id', 'page'),
'id' => '[0-9]+',
'page' => '[0-9]+'
)
);
and i does not work you can refer link
Is it possible to create an image with a link that also has a pop up alert [$confirmMessage] using the html helper in CakePHP?
This is my current text link:
$this->Html->link('Clear list', array('controller' => 'items', 'action' => 'clearlist', $model['Model']['id']), array(), 'Clear list?')
This how the image helper creates images with links:
echo $this->Html->image("recipes/6.jpg", array( "alt" => "Brownies", 'url' => array('controller' => 'recipes', 'action' => 'view', 6)));
However this allows only an htmlattributes array as the arguements for the link.
The $confirmMessage alert is not an html attribute is it?
This is the code I tried:
echo $this->Html->link($this->Html->image("clearall.png", array("alt" => "Clear list")), array('controller' => 'items', 'action' => 'clearlist', $model['Model']['id']), array(), 'Clear list?');
However this code printed the correct html for my img as text:
<img src="/img/clearall.png" alt="Clear list" />
Do I have to give up on htmlhelper in this case?
CakePHP does do this with the Html helper and you were really close!
<?php echo $this->Html->link($this->Html->image('clearall.png', array(
'alt' => 'Clear list')
), array(
'controller' => 'items',
'action' => 'clearlist',
$model['Model']['id']
), array(
'escape' => false,
'confirm' => 'Clear list?'
)); ?>
You could also have done it without the helper like so:
<a href="/items/clearlist/<?php echo $model['Model']['id']; ?>"
onclick="return confirm('Clear list?');">
<img src="/img/clearall.png" alt="Clear list" />
</a>
Thanks to ADmad and rtconner for showing me this in IRC.
HI,
im accessing my edit_view using the url
/controller/action/group_id/id
but when i check my action it is only using
/controller/action/id
i have already tried using the following.
$params = array('url' => array('controller' => 'controller','action'=> 'action',$group_id,$id))
$this->form(model,$params)
$params = array('url' => '/controller/action/group_id/id')
$this->form(model,$params)
but its still not working.
Thanks
Don't really know what $this->form() is, but try:
echo $this->Form->create('SomeModel', array(
'url' => array(
'controller' => 'controller',
'action' => 'action',
$param_1,
$param_2
)
));