2012-02-13 10 views
0

私の変数が私のビューに定義されていないというエラーが出ています。これは実際に私の最初の検索フォーム(ケーキのためだけではない)と私は間違っている必要があります確信しています。ここに私のコントローラコード: 更新コントローラアクションとhtmlフォームの両方の新しいコードはここにあります。私は、この出力を与える簡単なcakephp検索フォームがうまくいかない場合

<?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'); ?> 

<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> 

は今私のコントローラロジック:

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

} 

}

答えて

1

あなたはLodgings Controllerを使用しており、ユニットモデルを使用したいと思いますが、使用するユニットモデルはありますか?

public $uses = array('Unit','Lodging'); 

EDIT:

ビューは

<?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'); ?> 

コントローラー:

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

     } 
    } 
+0

はい、$ uses変数の下に読み込まれました。 – huzzah

+0

エラーコード – Bahdeng

+0

を貼り付けることができます。Cakeは検索ページに移動し、私のページには<?php debug($ type); ?>。 Cakeは私に言います.... "未定義の変数:タイプ[APP/View/Lodgings/search.ctp、line 1]" – huzzah

1
<input type="radio" value="house" name="data[Lodgings][type]">House 

モデルはユニットである、それはいけませんbe

<input type="radio" value="house" name="data[Unit][type]">House 
+0

を参照してください、それは私があまりにも思ったものだ、とそれは私がもともと持っていたものですが、私は同じエラーを取得します'タイプ'は定義されていません。 – huzzah

+0

'$ result- $ this-> Unit-> find( 'all'、array( 'conditions' => $ conditions));' '$ this-> log(print_r)を使って返されたデータをデバッグログに記録してみてください。 ($ result、true)、LOG_DEBUG); ' – JackOfAllTrades

+0

オクラ、私はそれをしました。今、私はその出力をどこで見つけるのですか? – huzzah

関連する問題