Answer the question
In order to leave comments, you need to log in
How to make navigation widget?
A little confused with the widget, how to display data through foreach. That is, I want to embed all the topics exactly there and shove everything as they are created
<?php
namespace frontend\components;
use app\models\Knowledge;
use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
class NavKnowledge extends Widget
{
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
}
public function run()
{
parent::run(); // TODO: Change the autogenerated stub
$name = ArrayHelper::map(Knowledge::find()->all(), 'id', 'title');
echo '<ul class="nav nav-pills nav-stacked">'.
foreach ($name as $key => $value){
echo '<li>'. Html::a($value, ['site/post', 'id' => $key]).'</li>';
}.'
</ul>';
return $name;
}
}
Answer the question
In order to leave comments, you need to log in
Why doesn't www.yiiframework.com/doc-2.0/yii-bootstrap-nav.html suit you ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question