These arenât part of the template but part of your project. We canât help with it.
An application created by app-basic template should have those navigation buttons defined in views\layouts\main.php
. Iâm sure you know it and have already customized them to your needs.
So what you want to do is to dynamically add/remove some buttons to/from the nav bar according to your conditions. Probably you could do it by checking the access rights of the current user.
I have already made the controls that the user and the administrator can see but the About Us, Contact Us buttons appear both in the backend and in the user and I do not want them to appear.
This is how I have defined my main
As you have already done for âproductoâ and others, you could do something like the following for the âContact Usâ button.
(is not admin) ? (Contact us button) : ("")
(is not admin)
should be replaced by something like (Yii::$app->user->isGuest)
or (!Yii::$app->user->can('admin'))
. It depends on how you organize the user rights.
BTW, please show us your code using code tag and text where applicable, rather than using screen shots.
this is code main.php
echo Nav::widget([
âoptionsâ => [âclassâ => ânavbar-navâ],
âitemsâ => [
[âlabelâ => âInicioâ, âurlâ => [â/site/indexâ]],
(!Yii::$app->user->isGuest)?(
['label' => 'Productos', 'url' => ['/producto/index']])
:("")
,
(!Yii::$app->user->isGuest)?(
['label' => 'Tiendas', 'url' => ['/tienda/index']])
:("")
,
(!Yii::$app->user->isGuest)?(
['label' => 'Categorias', 'url' => ['/categoria/index']])
:("")
,
(!Yii::$app->user->isGuest)?(
['label' => 'Carrusel', 'url' => ['/carousel/index']])
:("")
,
['label' => 'Nosotros', 'url' => ['/site/about']],
['label' => 'Productos', 'url' => ['/producto/lista']],
['label' => 'ContĂĄctanos', 'url' => ['/site/contact']],
Yii::$app->user->isGuest ? (
['label' => 'Iniciar sesion', 'url' => ['/site/login']]
) : (
'<li>'
. Html::beginForm(['/site/logout'], 'post', ['class' => 'form-inline'])
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>'
)
],
]);
NavBar::end();
?>
So, something like this:
(is not backend) ? (
['label' => 'Nosotros', 'url' => ['/site/about']])
: (""),
I canât tell what to replace (is not backend)
, because I donât know how you control access rights of the users. It depends on you.
I use the accesControl
How many kinds of users do you need?
Or, in other words, how do you distinguish frontend and backend?