CakePHP 2.x Paginaton: Remember which page you're one - cakephp

I'm working on a webshop. In the categories view we load the products in with jquery because the user is able to filter them. This works great.
We then tried to save the page the user was on (in the pagination), so that if he views a product and gets back to the categorie view, he starts on the page he was previously on. For example, I'm on pagination page 3, view a product, hit the browser back button, and continue on page 3 instead on 1 (which is default cakephp behaviour). We save the page number in a session, which works great as far as we can see. Then we read that pagenumber from the session and use it in our $this->paginate as 'page' => $pagenumber. This also works.
But there is one weird problem. When you start on page 2 or 3 (read: any page bigger than 1, but we only have 3 pages at the moment), you can't get back to page 1. Switching to page 2 or 3 works great, but you can't switch to page 1. If you click on it nothing happens, it does send a network request thingy in the chrome element inspector so something is happing in the background. If we manually set the page to 'page' => 1. It works, you can switch to all 3 pages.
I hope you understand my problem, I tried to explain it as best as I can. (Sorry if my English isn't too good, I tried the best I could).
My code (I made it as short as possible without fields en joins):
In the controller
$page_number = $this->Session->read('Pagination.currentpage');
$this->paginate = array(
'conditions' => array(
'Product.status' => 'active',
'Product.visibility' => 1,
'Product.hidden_on_site' => 0,
),
'order' => 'Product.name ASC',
'limit' => 20,
'recursive' => 2,
'page' => $page_number,
);
The $page_number works, it outputs the right page. But it gives the problem that you can't get tot page 1 if you're on page 2 or 3. If we manually set 'page' => 1 it works.
I hope you have a clue or a solution that works in an other way...

The CakePHP 2.x PaginationRecall Component works very well for this purpose. I use it in several of my projects.
Author is SO member Athanassios Bakalidis.

Related

CakePHP 4 Forms: do not preselect on multiple select

Here's the situation: I have a multi-staged tunnel that basically passes a user from page to page via form submits. Fill out stage one, click submit, get sent to page two and soforth. The trouble is that my fields are creating similarly-named form elements, so when the new page loads, Cake seems to see it as the same form as the previous one. Thus, the checkboxes selected in the first form get checked in the second form, even though they are of completely different values.
TL;DR is there a way to specify with this call that there should absolutely NOT be any prefilling of the fields?
<?= $this->Form->control('estimate_options.0.option_value', [
'type' => 'select',
'multiple' => 'checkbox',
'options' => $deliverables,
'label' => false,
'value' => !empty($selectedDeliverables->option_value) ? $selectedDeliverables->option_value : false,
]);
?>
As you can see, I'm attempting to pass "false" (I've also tried NULL) as the 'value' to specify that nothing should be selected, but they get checked anyway?

CakePHP 2 with CakeDC/I18n language prefix being lost

I have a CakePHP 2.5 site running with CakeDC/I18n plugin to allow for multi language support. I have installed the plugin to use a 3 letter prefix when switching languages:
www.example.com/eng/
This is working fine when I click a button to change languages. The language prefix is added to the url. The problem is when I switch pages by clicking on a link the prefix is dropped. Why would this be happening? Do I need to do something in the href markup? My understanding is that the CakeDC/I18n plugin would take care of this.
Any help would be greatly appreciated as I have been scratching my head with this one for awhile!
You need to pass as parameter the current language.
Otherwise it'll always use the default language that you defined in the bootstrap.php
Here is an example.
Router::url(
'lang' => 'spa',
'controller' => 'articles',
'action' => 'view',
'slug' => 'test'
);

how do I use the data in array in joomla list view as a link

I have the following code " which is not quite correct" in a part of a list view in my component. For Joomla 3.4
<td style="text-align:center">
<?php echo JDom::_('html.fly', array(
'dataKey' => 'link',
'dataObject' => $row,
'href' =>array($row->link),
'target' => '_blank'
));?>
I am trying to get the link from the field called link , but every thing I have tried either places the sites url before the link, does nothing or just goes back to the front page of the site. The link field contains a link to another website.
Can someone help me with this code snippet?

Submit always defaults to first submit button (multi-form)

Following the Examples Module in Drupal 7, I'm creating a multi-step form. Page 1 are the values, with a submit to go to page 2 (a sort of confirmation screen). On page 2, I have a submit and a back button.
According to Example #8 in the Examples module, we use a submit button for the back button, with a custom #submit handler, as so:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#submit' => array('my_final_submit_function'),
);
$form['back'] = array(
'#type' => 'submit',
'#value' => t('<< Back'),
'#submit' => array('my_back_button_handler_function'),
);
Everything works fine until I try to submit or hit back. Whichever button (submit or back) is placed first in the code is the button Drupal 7 registers as the clicked button, including in the form_state. Each function has their own #submit pointing to a different function. I have confirmed that Drupal can see/execute both functions.
Whichever submit button Drupal thinks was triggered is the #submit handler that gets processed.
When I put the back button first, both buttons trigger the back button functionality. When I put the submit button first, both trigger the submit logic. Although the examples module does not set a #name on each (to prevent name=op for both fields), I've tried doing that. I've tried it without that. It doesn't seem to make a difference.
I am not using an image_button, but a normal '#type'='submit'. Has anyone else encountered this issue?
You need to find out the trigger button like this
$form_state['triggering_element']['#value'] == 'Back'
That way you will sure what to do with the operation performed.

How to change url pagination in cakephp?

I want my url to change from this
/examinations/getchoices/page:2
to this
/examinations/getchoices/item/2
I wonder how to do this. I've already tried changing in the routes.php. I've tried the tutorial in this site. The page content doesn't change when I click prev or next links.
This is what i got in the url
/examinations/getchoices/ 2/ 2
My version of cake is 2.1.
Your help will be much appreciated. I've been stuck with this for 2 days already. Thank you.
You can define custom routes.
http://book.cakephp.org/2.0/en/development/routing.html
e.g.
Router::connect(
' /examinations/getchoices/item/:number',
array('controller' => 'examinations', 'action' => 'getchoices'),
array('pass' => array('number'))
);
let me know if i can assist you more

Resources