gpt4 book ai didi

mysql - 简单的 cakephp 搜索表单无法正常工作

转载 作者:行者123 更新时间:2023-11-29 08:58:35 25 4
gpt4 key购买 nike

我不断收到错误消息,表明我的变量未在我的 View 中定义。这实际上是我的第一个搜索表单(不仅仅是蛋糕),我确信我一定做错了。这是我的 Controller 代码:更新这是 Controller 操作和 html 表单的新代码。

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

现在我的 Controller 逻辑:

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

}

}

最佳答案

您正在使用 Lodgings Controller 并希望使用单位模型,您是否提到要使用的单位模型?

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

编辑:

查看

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

}
}

关于mysql - 简单的 cakephp 搜索表单无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9263230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com