gpt4 book ai didi

php - CakePHP 链接插件下拉列表未链接

转载 作者:行者123 更新时间:2023-11-29 11:00:00 24 4
gpt4 key购买 nike

我正在尝试使用链接插件来限制用户为错误的国家/地区选择城市。目前,当我没有选择任何国家/地区时,它可以让我从所有城市中进行选择。但一旦我选择了一个国家,它就不会让我选择任何城市。我已经使用 Chained 网站的代码让这个插件正常工作。我的 splinter 国家/城市版本可以在这里看到登录:访客密码: 密码 http://team.southpacificavionics.com/customers/add如果您将该网址上的“添加”更改为“测试”,则可以看到我的测试版本(抱歉,我无法发布更多链接)。我使用 ./cake cake 来创建我的客户、国家和城市 Controller 、模型、模板和关键关系。

You can see from this image that the cities are linked to countries

这是我为客户提供的 add.ctp

 <?php echo $this->Html->script('jquery.min'); ?>
<?php echo $this->Html->script('jquery.chained'); ?>

<script type="text/javascript">
$(document).ready(function () {
$("#cities").chained("#countries");
});
</script>

<script type="text/javascript">
$(document).ready(function () {
alert('java is working');
});
</script>

<?php
/**
* @var \App\View\AppView $this
*/
?>

<div class="customers form large-9 medium-8 columns content">
<?= $this->Form->create($customer) ?>
<fieldset>
<legend><?= __('Add Customer') ?></legend>

<?php
echo $this->Form->input('country_id', ['options' => $countries, 'empty' => true,'id'=>'countries']);
echo $this->Form->input('city_id', ['options' => $cities, 'empty' => true,'id'=>'cities']);

?>
</fieldset>

<?= $this->Form->end() ?>

这是我的mysql代码

CREATE TABLE IF NOT EXISTS `southpac_team`.`customers` (
`id` INT NOT NULL,
`country_id` INT NULL,
`city_id` INT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `southpac_team`.`countries` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `southpac_team`.`cities` (
`id` INT NOT NULL AUTO_INCREMENT,
`country_id` INT NOT NULL,
`name` VARCHAR(100) NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;

最佳答案

您没有在城市下拉选项中添加类别,但您应该在城市下拉列表中添加国家/地区 ID 作为类别

pic

如何在 CakePHP 下拉列表中添加类

$items = $this->Cities->find('all')->all()->toArray();
$cities = [];
foreach ($items as $key => $value) {
$cities[$key]['value'] = $value['id'];
$cities[$key]['text'] = $value['indent_no'];
$cities[$key]['class'] = $value['country_id'];
}

更多信息请查看extra attribute in dorpdown

关于php - CakePHP 链接插件下拉列表未链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42430052/

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