sanity check: Paginator, query string

2009-01-10 Thread brian

I have an element  for displaying Paginator's links which I can drop
into a pagination view, both above and below a set of paged data. So
far, it works just fine. But, I've had to do some fiddling to deal
with a query string and I'm really uncertain whether what I've done is
the best way. Of course, it might be the only way.

I've posted a basic version of the element here:
http://bin.cakephp.org/view/456211020

If the query string is set in the controller, it's added to
$this-params['url']['?'] just before Paginator's options are set with
$this-params['url']. This way, the links it creates get the query
string appended. So far, so good.

 But, in order to make limit links (next 20, next 30, etc.) the
limit in the URL's query string must first be removed or one gets
something like:

/search/index/page:2/limit:20?q=foobarlimit=10models=Member,Publication,Post

So, instead of echoing $paginators's next, prev, etc. methods
directly, I have to write them to variables, then check, once again,
for query string:

if (isset($query_string))
{
$this-params['pass']['?'] = preg_replace('/limit=[0-9]+/', '',
$query_string);

/* set the options once again
 */
$paginator-options(array('url' = $this-params['pass']));

/* empty for next element invocation
 */
$this-params['pass']['?'] = null;
}

... then go on to write the limit links and, finally, echo all of
those into my links div.

So, my question is: well, is this the best I can do? It seems a bit
hackish, for one, to do this in an element. Also, the element can be
dropped into a view several times.

I'd appreciate any comments. I'm wondering if this functionality
should be rolled into PaginatorHelper. If others agree, I'll write
something up and post it to Trac.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread Miles J

Why arent your query strings named parameters?

And then you put this in your view: $paginator-options(array('url' =
$this-passedArgs));
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread brian

The params--including limit--come in the first time through a form
(GET). The results are paginated, so in the view, I have a set of
links, as usual, plus links which would pass a new limit param.
Because I'm telling Paginator to include the query string, I need to
adjust before having it create these limit links.

You say to use $this-passedArgs but I was under the impression that
the way to get the correct URL was:

$paginator-options(array('url' = $this-params['pass']));

So, I'm confused.

On Sat, Jan 10, 2009 at 3:54 PM, Miles J mileswjohn...@gmail.com wrote:

 Why arent your query strings named parameters?

 And then you put this in your view: $paginator-options(array('url' =
 $this-passedArgs));
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread Miles J

Ive done it that way before, and it also shows that in the cookbook.

http://book.cakephp.org/view/166/Pagination-in-Views
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread brian

I got it working. Thanks a bunch for setting me straight!

For posterity, this is what I needed:

public function index()
{
/* defaults
 */
$page = 1;
$limit = $this-SearchIndex-limit;
$models = array();

/* check form query
 */
if (!empty($this-data))
{
if (empty($this-data['Search']['q']))
{
$this-flash('no search string');
}

$q = $this-data['Search']['q'];

// and limit  models ...
}
else if (!empty($this-params['named']))
{
/* in URL
 */
if (empty($this-params['named']['q']))
{
$this-flash('no search string');
}

$q = $this-params['named']['q'];

// and limit  models ...

$page = $this-params['named']['page'];

}

if (isset($q))
{
/* now make sure things are clean
 */
App::import('Sanitize');
$q = Sanitize::escape($q, 'default');
$limit = intval($limit);

// ...

/* set this for Paginator
 */
$this-passedArgs = array(
'q' = $q,
'models' = implode(',',$models),
'limit' = $limit
);
$this-SearchIndex-searchModels($models);

$this-paginate = array(
'limit' = $limit,
'page' = $page,
'conditions' =  MATCH(SearchIndex.data) 
AGAINST('${q}' IN BOOLEAN MODE)
);
$this-set('results', $this-paginate('SearchIndex'));
$this-set('search_string', $q);
}

// etc.
}

views/elements/paginator_links.ctp:

$paginator-options(array('url' = $this-passedArgs));

div class=PaginationLinks
?= $paginator-prev(
'20',
array(
'url' = array('limit' = 20),
'class' = 'Limit LimitPrev',
'title' = 'previous, limit 20 results'
)
) ?

...

Works a treat! I *knew* what I'd done was hackish. While it worked, I
was sure there had to be a better way. I'm glad I checked in.

On Sat, Jan 10, 2009 at 6:06 PM, Miles J mileswjohn...@gmail.com wrote:

 Ive done it that way before, and it also shows that in the cookbook.

 http://book.cakephp.org/view/166/Pagination-in-Views
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread Miles J

Very good.

One thing id like to point out is that you should stop using ?= and
use ?php echo. ?= will deprecated in the next version of php and
also doesnt work correctly on some server configs.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: sanity check: Paginator, query string

2009-01-10 Thread brian

The server config is mine alone, so I don't care about that. But I
didn't know about the deprecation, thanks. That's too bad, if true. I
really hate having to use echo and a semi-colon in my view code.

On Sat, Jan 10, 2009 at 7:46 PM, Miles J mileswjohn...@gmail.com wrote:

 Very good.

 One thing id like to point out is that you should stop using ?= and
 use ?php echo. ?= will deprecated in the next version of php and
 also doesnt work correctly on some server configs.
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---