Reputation: 1805
I keep getting the error that my variable is not defined in my view. This is actually my first ever search form (not just for cake) and I'm sure I must be doing it wrong. here is my controller code: UPDATE Here is the new code, both for the controller action and the html form.
<?php
$options = array('house' => 'House', 'condo' => 'Condo', 'hotel'=>'Hotel');
$attributes = array('legend' => 'Property:<span style="font-style:italic">(Please select one)</span>');
echo $this->Form->radio('Unit.type', $options, $attributes);
?>
<?php echo $this->Form->end('Search'); ?>
which gives me this output:
<form action="/lodgings/search" id="UnitIndexForm" method="get" accept-charset="utf-8">
<fieldset><legend>Property:<span style="font-style:italic">(Please select one)</span></legend>
<input type="hidden" name="type" id="UnitType_" value=""/><input type="radio" name="type" id="UnitTypeHouse" value="house" />
<label for="UnitTypeHouse">House</label>
<input type="radio" name="type" id="UnitTypeCondo" value="condo" />
<label for="UnitTypeCondo">Condo</label>
<input type="radio" name="type" id="UnitTypeHotel" value="hotel" />
<label for="UnitTypeHotel">Hotel</label>
</fieldset>
<div class="submit">
<input type="submit" value="Search"/>
</div>
</form>
Now my controller logic:
function search() {
$result = array();
if (isset($this->params['url'] ))
{
$type = $this->params['url'];
$conditions = array("Unit.type = " => $type, 'Unit.active'=>1);
$result = $this->Unit->find('all', array('conditions'=> $conditions));
$this->log(print_r($result, true));
$this->set('type', $result);
}
}
Upvotes: 0
Views: 305
Reputation: 434
You are using the Lodgings Controller and want to use the Unit model, did you mention the unit model to use ?
public $uses = array('Unit','Lodging');
EDIT:
view
<?php
echo $this->Form->create(false, array('id'=>'search', 'url'=>array('controller' => 'lodgings', 'action'=>'search')));
$options = array('house' => 'House', 'condo' => 'Condo', 'hotel'=>'Hotel');
$attributes = array('legend' => 'Property:<span style="font-style:italic">(Please select one)</span>');
echo $this->Form->radio('type', $options, $attributes);
?>
<?php echo $this->Form->end('Search'); ?>
Controller:
function searchr(){
$result = array();
if (isset($this->data['type']))
{
$type = $this->data['type'];
$conditions = array("Unit.type = " => $type, 'Unit.active'=>1);
$result = $this->student_info->find('all', array('conditions'=> $conditions));
$this->log(print_r($result, true));
$this->set('type', $result);
}
}
Upvotes: 1
Reputation: 1063
<input type="radio" value="house" name="data[Lodgings][type]">House
Where the model is Unit, shouldn't it be
<input type="radio" value="house" name="data[Unit][type]">House
Upvotes: 1