I am trying to limit a search by a field chosen using a form. My
method currently works but is very dirty (unclean urls, passing value
through "get", etc.) and was hoping someone here could provide me an
alternative method. Here is the current pertinent code:
<form action="/drugs/category" method="get">
<li>
<select id="category" name="category">
<option value="">Select category</option>
<option value="adhd">ADHD</option>
<option
value="antihistamine">Antihistamines</option>
<option value="benzo">Benzos</option>
<option value="diabetes">Diabetes</option>
<option value="ed">ED</option>
<option value="top20">Top 20</option>
<option value="zdrug">ZDrugs</option>
</select>
</li>
<li><input type="submit" value="Flashcards by category"
/></li></
form>
function category($id=null){
$category=$_GET['category'];
// If no category or id, go to /cards
if(!$category && !$id) $this->redirect(array('controller' =>
'drugs', 'action' => 'cards'));
if(!$id){
$drug = $this->Drug->find('first',
array('conditions'=>array('category like'=>"%".$category."%")));
} else {
$drug = $this->Drug->findById($id);
}
$params = array(
'conditions' => array('category like' =>
"%".$drug['Drug']
['category']."%"), // Just category
'recursive' => 0,
'field' => 'id',
'value' => $drug['Drug']['id']
);
$neighbors = $this->Drug->find('neighbors', $params);
$this->set(compact('drug', 'neighbors'));
}
It is working here: http://rx.campushott.com/
And in practice I get URLS like this:
http://rx.campushott.com/drugs/category/63?category=ADHD
and I'd prefer something more like this:
http://rx.campushott.com/drugs/category/63/ADHD
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en