我正在尝试学习 Yii2 框架。有人可以帮我解决这个问题,我真的很感激。卡在两件事上,过滤 CRUD 中的数据并在导航栏上的 ('reserveringen) 处添加一个下拉菜单。 Image database names Tafel = Table(翻译)
[Image database names][1]
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use app\widgets\Alert;
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php $this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Yii::$app->name,
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'my-navbar navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Serveren', 'url' => ['/overzicht/index' ]],
[
'label' => 'Reserveringen',
'items' => [
['label' => 'Reservering weergeven', 'url' => '/reserveringen/index'],
['label' => 'Reservering maken', 'url' => '/reserveringen/create'],
],
['label' => 'Gegevens', 'url' => ['/eten/index' ]],
// ['label' => 'About', 'url' => ['/site/about']],
// ['label' => 'Contact', 'url' => ['/site/contact']],
Yii::$app->user->isGuest ? (
['label' => 'Login', 'url' => ['/site/login']]
) : (
'<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>'
)
],
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer">
<div class="container">
<!-- <p class="pull-right"><?= Yii::powered() ?></p> -->
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
Another thing I'm stuck at is the option to filter the CRUD by selecting a data Trying to make a select option where the person can filter the table number. 1 to 5. For example when 1 is selected only the datas with table 1 appear.
我遇到的另一件事是通过选择一个数据来过滤 CRUD 的选项 试图做出一个选择选项,人们可以在其中过滤表号。 1 到 5。例如选择 1 时只出现表 1 的数据。
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel app\models\bestellingSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Bestelling maken';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="bestelling-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Maak een bestelling aan', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php $menuSort=[1=>'1' ,2=>'2' ,3=>'3' ,4=>'4' ,5=>'5'];
?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'ID',
'Artikel:ntext',
'Table',
[
'attribute'=>'Table',
'label' => 'Table',
'filter'=>$menuSort,
'contentOptions' => ['style' => 'width:200px; white-space: normal;' ],
'format' => 'raw',
'value' => function ($model) use ($menuSort) { return $menuSort[$model->type];}
],
// 'filter'=>$menuSoorten,
'Prijs',
'Totaal',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
[1]: https://i.stack.imgur.com/PT8Qu.png