Cakephp-2.5 next navigation url without html code - cakephp

How can I get next navigation url without html code ?
$this->Paginator->next();
//output
Next
I just need url only.

The paginator helper itself doesn't support that, the least HTML'd return value (tag => false) is a simple anchor element, so you'll have to build the URL on your own, which is pretty simple tough.
What you need is the current page number, this can be retrieved via PaginatorHelper::params(), the page key in the returned array holds the current page.
All you have to do then is add 1 to it, and pass a URL array with the key page and the new page number as its value to Router::url() and you'll get the URL for the next page:
$params = $this->Paginator->params();
$url = array(
'page' => $params['page'] + 1
);
echo Router::url($url);
ps. you might want to check whether there is actually a next page using PaginatorHelper::hasNext()
if($this->Paginator->hasNext())
{
// ...
}

Related

how to do not to go directly index.ctp when only cakephp/Controller/ instant of cakephp/Controller/index.ctp

Controller Name : SaleController.php
action name : index.ctp
When I write localhost/cakephp/Sale/index is written in address bar,
index page of SaleController is shown.
When I write localhost/cakephp/Sale/ is written in address bar,
index page of SaleController is shown.
Now,problem is I don't want to go index file when localhost/cakephp/Sale/ is written.
My cakephp version is 2.5.7.
If know ways,help me plz.
there is a lot of solutions :
Select view in the controller
in your SaleController.php
function index(){
$this->view="nameview.ctp";
}
Routes :
Router::connect(
'Sale/',
array('controller' => 'Sale' , 'action'=>'youraction' ),
array('option' => 'matchingRegex')
);
Select an other action in index
function index(){
$this->actionName();
}
First of all, your controller name should be SalesController (plural s).
Second, action is a method within controller not a file (here index mehod).
Third, index.ctp is a view file.
Fourth, you can change view in action method with render function (e.g. $this->render('other.ctp'); )
Fifth you can have custom URLs with routes.
And last but not least! you've not grabbed a good understanding of the framework, It's better to restudy the documentation.

Display module form on admin pages. Drupal 7. Commerce.

I've created a small module that I would like to link account notes with users.
I have written the beginnings of the module that includes a form for adding notes and date created. This works when I access mydomain.com/admin/user_notes.
My question is, how do I get this form to display in the admin section of the site on a users orders history page. eg mydomain.com/users/1245/order-history
I would like our admins who have a specific role to be able to add notes when they view a users order history page.
Thanks in advance for any advice.
you could use a block, create one with the hook_block_info and hook_block_view function.
Like this:
function tips_block_info() {
$block['yourBlockName'] = array(
'info' => t('This my created block'),
'cache' => DRUPAL_NO_CACHE, // Disable caching if you need/want to
);
return $block;
}
Thisby will create an empty block, to fill it with content use hook_block_view:
function moduleName_block_view($delta = '') {
$block = array();
switch($delta) {
// The delta of your block will be the key from the $block array we set in hook_block_info
case 'yourBlockName':
// Set the block title
$block['subject'] = 'Hey I\'m your block title';
$block['content'] = 'Block content goes here can also be the output of any function';
break;
}
return $block;
}
Don't forget to set access permission for your block if you need any, you can do that by editing the block on the block admin page.
Relevant Drupal API links:
hook_block_info
hook_block_view

Getting current page in CakePHP pagination

On one of my webpage, I show a list of customer details with default pagination [Paginator helper]. Each customer row has a corresponding 'edit' button which when clicked shows a DIV populated with that customer information. [This DIV has textboxes etc. where I can change customer info] After re-entering/modifying customer details, when I click on "Save" button, 2 ajax calls are made..
First one to save the edited record
The second one Updates the customer Listing on the same page with modified information
My problem : If I am on page 3 and edit one customer record, the 2nd ajax call refreshes the list but does not go to the page 3. It starts from page 1.
Please help.
You can get your current page here:
<?php echo $this->Paginator->counter(array(
'format' => ('{:page}')
)); ?>
This is part of the solution. :)
You can get your current page here:
$this->request->params['named']['page']
Did you try to use the link from Paginator? It maintains the page # to the controller.
Something like
// same parameters as $this->Html->link
<?php echo $this->Paginator->link( ... ) ?>
Check also the reference documentation for the Paginator Helper
I use jquery / javascript to store the page on a cookie and then read it from the controller.
// -------------------------------------------------------------------------
// on action click remember current page
$('td.actions').click( function( event )
{
var page = $('li.active a').html();
var name = window.location.href.split('-').join('_').split('/').pop();
$.cookie.raw = true;
$.cookie( 'CakeCookie[' + name + '_page]', page, { expires: 365, path: '/' } );
});

CakePHP Write URL path from initial search() action pagination array

I've hit a roadblock and cannot for the life of me get over.
I have a search() action which is working as expected.
From that function, I pass my pagination value to the results page and I get an array like so:
Array
(
[controller] => plans
[action] => search
[0] => 35
[1] => 0
[2] => 0
[3] => 1
[4] => 97389
)
ALL search results display correct (and array data is correct). BUT my url ONLY displays the Model and Action value when the initial results are displayed like so:
...plans/search
And if I do a paginator() *sort()* (in my header fields) or Next >> my pagination array prints to the url like so:
...plans/search/45/0/0/0/97389/page:1/sort:monthly_cost/direction:desc
Everything is working as expected BUT I need my initial search to display the url path as it does when paginator() or sort() is used.
I've tried imploding the array and tacking it onto the url (no dice).
I've tried to rewrite the url with the array (but this conflicts with the pagination)..
I've tried a bucket load of get and post ideas.. (no dice)..
Am I overlooking something VERY simple here? Someone please send any ideas you might have. This is kicking my butt!
I finally solved this:
In my search function, this is what I did:
if($this->RequestHandler->isPost()) {
$this->Session->write('search_form_sess', $this->data);
$initial_url = $ApplicantAge . '/' . $SpouseAge . '/' . $NumberChildren . '/' . $Vision . '/' . $Zip;
$this->redirect(array('action' => 'search', $initial_url));
exit();
}
As you can see I am also capturing the search form session data to pass to the search form to hold the search values in the inputs.

Filtering data using ajax observefield

I ve tried to implemented filtering data (list base on selected category) using dropdown with observefield and ajax pagination. I use session to remember selected category in order to keep pagination.
Here is my code (Cakephp 1.2)
In view :
echo $form->select('Category.id', $categories, null, array('id' => 'categories'),'Filter by Categories')
echo $ajax->observeField('categories' ,array('url' =>'update_category','update' => 'collectionDiv'));
In Controller:
if(!empty($this->data['Category']['id']))
{
$cat_id=$this->data['Category']['id'];
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection', $filters));
$this->Session->write($this->name.'.$cat_id', $category_id);
}
else
{
$cat_id=$this->Session->read($this->name.'.cat_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection'));
}
The filter work as I wanted but the problem is when I select empty value('Filter by Category) it still remember last category session so I can't back to the default list (All record list without filter).
I've tried to make some condition but still not success. Is there another way? Please I appreciate your help. thank
hermawan
Perhaps I don't understand the question, but it looks to me like it might be worth changing:
else
{
$cat_id=$this->Session->read($this->name.'.cat_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection'));
}
to:
else
{
$this->set('collections', $this->paginate('Collection',array()));
}
In effect your code appears to be doing this anyway. Check what the URL is at the top of the browser window after it has returned. Does it still contain pagination directives from the previous query?
You might want to review http://book.cakephp.org/view/167/AJAX-Pagination and make sure you've 'ticked all the boxes'.
I got it, It work as I hope now. I my self explain the condition and solution.
When I select category from combobox, then it render the page the code is :
If ($this->data['Category']['id']) {
$cat_id=$this->data['Category']['id'];
$this->Session->write($this->name.'.category_id', $category_id);
// I will use this session next when I click page number
$filters=array('Collection.art_type_id' => $category_id);
$this->set('collections', $this->paginate('Collection', $filters));
}else{
//if clik page number, next or whatever, $this->data['Category']['id'] will empty so
// use session to remember the category so the page will display next page or prev
// page with the proper category, But the problem is, when I set category fillter to
// "All Category" it will dislpay last category taked from the session. To prevent it
// I used $this->passedArgs['page']. When I clik the page paginator it will return
// current number page, but it will be empty if we click dropdown.
if (!empty($this->passedArgs['page']) {
$cat_id=$this->Session->read($this->name.'.category_id');
$filters=array('Collection.category_id' => $cat_id);
$this->set('collections', $this->paginate('Collection',$filters));
}else{
$this->set('collections', $this->paginate('Collection'));
}
}
From this case, I think that observefield will not send passedArg as we get from url such from ajax link or html->link. I hope this will usefull to anybody

Resources