如何设置从数据库中选择框的值,该值将加载到'change'cakephp中另一个选择框的事件


How to set a value to select box from the database which value will load on 'change' event of another select box in cakephp?

我有国家(id,country)和州(id,country_id,state)模型国家有许多州

各国控制者

在html

<li><?php echo $form->input('bcountry', array('empty' => 'Select Country', 'options' => $countries, 'id' => 'bco', 'label'=>'Country')); ?></li>
<li><div id="msg7"></div></li>
<li><div class="ajax_loading_image"></div></li>
<li><?php echo $form->input('bstate', array('type' => 'select', 'empty' => 'Select State','id' => 'bst','label'=>'State')); ?></li>
<li><div id="msg6"></div></li>

当我们选择国家时,它会加载状态。

但是我想要的是一旦数据被保存,如果用户再次访问该页面,我想要保存的数据被填写在各自的字段。只有国家字段显示先前保存的数据,但不显示状态字段,因为我在国家的变化事件中加载状态内容。

请帮助我走出这个问题,因为我是php和cakephp的新手。

为简单起见,先尝试将代码更改为cake默认值。例如

<?php echo $form->input('bcountry'); ?>

如果它自动填充,则问题出在您在'bcountry'后面的可选数组中指定的选项之一。

如果它仍然不能工作,那么尝试调试$this->data的输出,看看您是否真的访问了正确的信息:

debug ($this->data);

如果在调试输出中没有看到您希望打印的信息,则您的模型有问题。