Hi
I’m attempting to build a Yii2 widget management admin interface that I can use use to configure and store certain widget instances to a MySQL database for later retrieval and display.
My main issue is how to store a custom widget config array to the db whilst still allowing calls such as
Yii::$app->user->identity->username
to be called upon retrieval at runtime.
Basic serialization would not allow this (it would store the value from the call rather than the code) and I’m not too keen on using eval.
Essentially, can anyone recommend a good way of storing to db and retrieving something like the following config from the app-advanced template whilst keeping the advantages of hard coded configs? …
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
Any help, thoughts or ideas will be much appreciated.