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:

<div>Property: <?= $this->formSelect('property', $this->property, array('style'=>'width:150px'), $this->properties) ?></div>

Open in new window


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>

Open in new window


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?
LVL 8
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rgranlundAuthor Commented:
At the bottom is the statement but I'm not sure where it goes:
public function pnlsAction()
{
	$db = Stax_Db::getConnection();
	$where = array();
	//if ($this->_getParam('search') != "") {
	//			$where[] = 'vendor_name LIKE "%' . $this->_getParam('search') . '%"';
	//			$this->view->search = $this->_getParam('search');
	//		}
	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));

	/*
	$table = new Db_PNLs();
	$sel = $table->select();
	$sel->where('property_id = ?',$props[0]->property_id);
	*/
	$paginator = Zend_Paginator::factory($records);
	$paginator->setCurrentPageNumber($this->_getParam('page'));
	$paginator->setItemCountPerPage(50);

	$availableProperties = array();
	if ($this->user->access != Stax_User::ACCESS_ADMIN) {
		foreach ($this->user->getProperties() as $current) {
			$availableProperties[$current->property_id] = $current->name;
			//if(isset($_POST['property'])) {echo 'value="'.$_POST['property'].'"';}
		}
	} else {
		$availableProperties = $db->fetchPairs("SELECT property_id, name FROM properties WHERE active = '1' ORDER BY name");
	}
	$availableProperties = array(''=>'Select a Property') + $availableProperties;

	$this->view->properties = $availableProperties;
	$this->view->paginator = $paginator;
	
//if(isset($_POST['property'])) {echo 'value="'.$_POST['property'].'"';}
}

Open in new window

0
RobOwner (Aidellio)Commented:
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:

if (is_numeric($this->_getParam('property'))) {
		$where[] = 'property_id = ' . $db->quote($this->_getParam('property'), Zend_Db::INT_TYPE);
		$this->view->property = $this->_getParam('property');
	}

Open in new window


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>

Open in new window

0
rgranlundAuthor Commented:
@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:

	$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));

Open in new window


How would I do this:

<div>Property: <?= $this->formSelect('property', $this->property, array('style'=>'width:150px'), $this->properties If(isset($_POST['property'] [echo 'checked="check"'}); ?></div>
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

RobOwner (Aidellio)Commented:
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.
0
rgranlundAuthor Commented:
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.
0
RobOwner (Aidellio)Commented:
Then it's not posting back the 'property' value as you're expecting.

Can you confirm that it is in fact posted back each time?

Before this line add print_r($_REQUEST['property']); and post back the results

if (is_numeric($this->_getParam('property'))) {
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
@tagit:
When I do this:
"Before this line add print_r($_REQUEST['property']); 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/page/2/
0
RobOwner (Aidellio)Commented:
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.
0
RobOwner (Aidellio)Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.