Robert Granlund
asked on
MVC ZEND Framework and select options
I'm looking through a piece of code Built on the Zend Framework. The following line generates a Select Dropdown:
it appears like this on the webpage:
The code filters it by location; Alhambra, Banning etc. It has an output of 10 locations in each city and then Paginates to the next page and shows 10 more results and so on. However, when you paginate to the next page, it looses the filter. If you had chose Alhambra and there are 100 returns, you see the first 10. Go to the next page and it is no longer filtered by Alhambra. Can anyone shed any light on how I maintain the filter? Do I need to start a session?
<div>Property: <?= $this->formSelect('property', $this->property, array('style'=>'width:150px'), $this->properties) ?></div>
it appears like this on the webpage:
<select id="property" style="width:150px" name="property">
<option label="Select a Property" value="">Select a Property</option>
<option label="Alhambra" value="42">Alhambra</option>
<option label="Banning" value="49">Banning</option>
<option label="Barstow" value="1">Barstow</option>
<option label="Bedford Pancakes" value="25">Bedford Pancakes</option>
<option label="Boulder" value="4">Boulder</option>
</select>
The code filters it by location; Alhambra, Banning etc. It has an output of 10 locations in each city and then Paginates to the next page and shows 10 more results and so on. However, when you paginate to the next page, it looses the filter. If you had chose Alhambra and there are 100 returns, you see the first 10. Go to the next page and it is no longer filtered by Alhambra. Can anyone shed any light on how I maintain the filter? Do I need to start a session?
Lines 9 to 12 above indicates to me that if the filter has been set then get the property (from the $_POST i suspect) and then set the property in the view:
So the first snippet of code you posted, that's in the view right? Try dumping the $this->property just before the select:
if (is_numeric($this->_getParam('property'))) {
$where[] = 'property_id = ' . $db->quote($this->_getParam('property'), Zend_Db::INT_TYPE);
$this->view->property = $this->_getParam('property');
}
So the first snippet of code you posted, that's in the view right? Try dumping the $this->property just before the select:
<div>Property: <? echo print_r($this->property,true) . "<br>"; echo $this->formSelect('property', $this->property, array('style'=>'width:150px'), $this->properties) ?></div>
ASKER
@tagit, that did not work. However, I think I have a clue.
The script says basically choose all records or choose WHERE. How can I switch them? The script is as follows:
How would I do this:
<div>Property: <?= $this->formSelect('propert y', $this->property, array('style'=>'width:150p x'), $this->properties If(isset($_POST['property' ] [echo 'checked="check"'}); ?></div>
The script says basically choose all records or choose WHERE. How can I switch them? The script is as follows:
$where = array();
if (is_numeric($this->_getParam('property'))) {
$where[] = 'property_id = ' . $db->quote($this->_getParam('property'), Zend_Db::INT_TYPE);
$this->view->property = $this->_getParam('property');
}
$where = count($where) ? $where : $this->getProps($db);
$records = $this->user->getAllPNLs(implode(' OR ',$where));
How would I do this:
<div>Property: <?= $this->formSelect('propert
I think you should check it's posting the data ok:
$this->_getParam('property ') should be getting the posted value of the select element but it's also checking if it is numeric, which looks correct given the values of each town is a number.
I think you can also use $this->getPost('property') , which is worth trying to see if it holds the value you expect it to.
Regarding the "where", that code looks right in that it's saying if you selected a value in the select then use and remember that. I suspect that the $this->_getParam('property ') isn't returning what you expect it to hence my suggetion to output it to the browser so you can see if it is remembering what you are selecting each time.
$this->_getParam('property
I think you can also use $this->getPost('property')
Regarding the "where", that code looks right in that it's saying if you selected a value in the select then use and remember that. I suspect that the $this->_getParam('property
ASKER
The number prints to the page when it is first selected. However, when I paginate to the next page, it is not there. AND the weird thing is, when I go to the next page, it shows me all of the results that should be on the next page if I had not filtered. AND if I choose the same city again and filter it shows me the second page of results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@tagit:
When I do this:
"Before this line add print_r($_REQUEST['propert y']); and post back the results"
When I filter the first time, it prints the number but when I click next it does not. However, If I filter again, it gives me the second page of the original results. Actually, it gives me the second page of anything I filter on.
It is not retaining the value. In addition, when I first filter, the url looks like this:
MYSITE.com/reports/pnls/
When I click the NEXT button the ZEND Framework pagination changes the url to this:
MYSITE.com/reports/pnls/pa ge/2/
When I do this:
"Before this line add print_r($_REQUEST['propert
When I filter the first time, it prints the number but when I click next it does not. However, If I filter again, it gives me the second page of the original results. Actually, it gives me the second page of anything I filter on.
It is not retaining the value. In addition, when I first filter, the url looks like this:
MYSITE.com/reports/pnls/
When I click the NEXT button the ZEND Framework pagination changes the url to this:
MYSITE.com/reports/pnls/pa
Thanks for doing that, I just needed to be sure that it wasn't sending firm data to the php script but is in fact doing a url rewrite.
I won't be able to look at this for at least a day so feel free to request attention if you need this more urgently but I'll definitely check back then.
I won't be able to look at this for at least a day so feel free to request attention if you need this more urgently but I'll definitely check back then.
Are you able to show me the rendered Html of the page with this dropdown on it? ie right click the page, view source, copy and paste here
ASKER
Open in new window