正如您所看到的,像柏林这样的城镇是重复的。此外,我使用下面的代码块在下拉列表中显示它们:
# my_module.links.menu.yml
my_module.custom_links:
deriver: \Drupal\my_module\Plugin\Derivative\CustomLinkDerivative
我已经尝试在查询中使用 Distinct 类型,但没有成功。应该是别的吗?这是我的 stade_id
<?php
namespace Drupal\my_module\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CustomLinkDerivative extends DeriverBase implements ContainerDeriverInterface {
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static();
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$links['custom_menulink'] = [
'title' => t('Custom menulink'),
'menu_name' => 'main',
'route_name' => 'entity.node.canonical',
'parent' => footer,
'route_parameters' => [
'node' => 1,
]
] + $base_plugin_definition;
return $links;
}
}
答案 0 :(得分:0)
在这个函数的帮助下,您可以做一件事使结果成为唯一数组。
function unique_array($array)
{
$result = array_map("unserialize", array_unique(array_map("serialize", $array)));
foreach ($result as $key => $value)
{
if ( is_array($value) )
{
$result[$key] = $this->unique_array($value);
}
}
return $result;
}
将此功能添加到您的代码中,然后在获取city的结果后调用它,就像这样
$cities=$this->unique_array($cities);
它将为您提供所需的唯一数组,可以解决您的问题。
答案 1 :(得分:-1)
您可以使用查询问题
`select ID, post_title from $wpdb->posts where post_type = 'place' and post_parent = $state_id GROUP BY post_title`