我试图将tabsx用于不同的选项卡,并且每个选项卡都会显示不同的过滤数组。当我使用基本视图或基本数据显示时,但我尝试使用foreach过滤器数组,但发生未定义变量错误。 首先,我要在Web服务中获取数据,然后根据所显示的选定选项卡数组进行过滤。
sitecontroller.php
public function actionUnisweb2($fkid)
{
$options = array(
'login' => 'xxxx', 'password' => 'yyyy',
'cache_wsdl' => 0,
'trace' => 1,
'stream_context' => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)));
$client = new \SoapClient("xxxxxxxx?wsdl", $options);
$akademisyenler = $client->GetAcademiciansByUnitId($fkid);
foreach ($akademisyenler as $kisi) {
$list[$kisi->TcNo] = $client->GetPublications($kisi->TcNo);
}
$listtek = call_user_func_array('array_merge', $list);
$list2['deger']=$listtek;
$this->layout = 'xxx';
return ($this->render('unisweb',['fkid'=>$fkid,'list'=>$list2]));
}
views / site / unisweb.php
<?php
use kartik\tabs\TabsX;
use yii\helpers\Url;
?>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js" crossorigin="anonymous"></script>
<?php
$m="Makale";
$b="Bildiri";
$k="Kitap";
$items =
[
['label'=>'<i class="fas fa-chevron-right"></i> Tüm',
'encode'=>false,
'content' => (Yii::$app->controller->renderPartial('_view', ['model' => json_encode($list)])),
],
[
'label'=>'<i class="fas fa-user"></i> Makale',
'items'=>[
[
'label'=>'<i class="fas fa-chevron-right"></i>'.date('Y'),
'options' => ['id' => 'makaleY'],
'encode'=>false,
'content'=>'',
'linkOptions'=>['data-url'=>Url::to(['/site/fetch?fkid='.$fkid.'&tab='.$m.'&yil='.strval(date('Y'))])]
],
[
'label'=>'<i class="fas fa-chevron-right"></i>'.strval(date('Y')-1),
'encode'=>false,
'options' => ['id' => 'makaleZ'],
'content' => (Yii::$app->controller->renderPartial('contact_form2', ['model' => json_encode($list), 'yil'=>strval(date('Y')-1)])),
],
],
],
];
echo TabsX::widget([
'id' => 'tab-term-plan',
'items' => $items,
'position' => TabsX::POS_ABOVE,
'encodeLabels' => false]);
?>
我尝试链接选项或内容属性,但未响应。 我的第一个标签工作是显示所有数据数组。
当我单击“ id = makaleY”标签时,链接选项会调用提取操作,该操作会运行,但会返回错误。
当我在显示的foreach之前回显$ secili_tur变量时,但此变量未在foreach中定义。 在这段代码中,我想在所有数组中过滤今年的数据,所以我使用了foreach和array_filter。
sitecontroller.php
public function actionFetch($fkid,$tab,$yil)
{
$options = array(
'login' => 'xxxx', 'password' => 'yyyyy',
'cache_wsdl' => 0,
'trace' => 1,
'stream_context' => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)));
$client = new \SoapClient("xxxxxx?wsdl", $options);
$akademisyenler = $client->GetAcademiciansByUnitId($fkid);
foreach ($akademisyenler as $kisi) {
$list[$kisi->TcNo] = $client->GetPublications($kisi->TcNo); //tüm akademisyenlerin listesi
}
$listtek = call_user_func_array('array_merge', $list);
$list2['deger']=$listtek;
$secili_yil=$yil;
$secili_tur=$tab;
if ($secili_tur == 'Makale') {
$sorgu='($value->TurKod === "MAKALE_DIGER" or $value->TurKod === "MAKALE_TAM")';
}elseif ($secili_tur == 'Bildiri' ) {
$sorgu='($value->TurKod === "BILDIRI")';
}elseif ($secili_tur == 'Kitap') {
$sorgu='($value->TurKod === "KITAP_BOLUM" or $value->TurKod === "KITAP_ARASTIRMA")';
}else{
$sorgu='(1==1)';
}
foreach ($list2 as $key => $value) {
$sonuc = array_filter($value, function($value){
if (isset($value->BasimTarih) and isset($value->TurKod)) {
$a=$value->BasimTarih;
$yayinyili=substr($a, (strlen($a)-4),4);
if ($yayinyili === $secili_yil ) return true;
}
return false;
});
}
//return $this->renderPartial('_view', ['sonuc'=>json_encode($sonuc)]);
//return Yii::$app->controller->renderPartial('_view', ['sonuc'=>json_encode($sonuc)]);
return Json::encode($sonuc);
}
感谢帮助。