I'm wondering if https://github.com/kartik-v/yii2-widget-sidenav is capable of showing a page that is not the 'active item' as active. An example being I have my menu item set at 'active' => ($item == 'site/home'), but I would like to essentially have site/home2 show the same menu item as active. Treating it as a child page within the same controller.
Thanks!
Yes, you can specify which menu item should be active on any particular URL.
For example:
['label' => 'Home', 'icon' => 'home', 'url' => Url::to(['/site/home', 'type'=>$type]), 'active' => ($currentPage == 'page1')],
here 'active' specify the codition on which this menu should be active.
so in your case:
'active' => ($item == 'site/home' || $item == 'site/home2')
Related
This is my actionIndex() in my controller.
public function actionIndex()
{
$featured= new ActiveDataProvider([
'query'=>News::find()
->where(['not', ['featuredOrder' => null]])
->orderBy('featuredOrder'),
]);
$checkList=Featured::find()
->joinWith('news')
->where(['news.featuredOrder'=>null])
->orderBy('featuredOrder')
->all();
return $this->render('index', [
'dataProvider' => $featured,
'checkList'=>$checkList,
]);
I have a listview in my index view which is rendered by this controller. If an item of the listview is clicked, it will display the detailView of each item, along with the update button to update the item's data which will generate a form to update. I need to pass the $checklist to this form. Later I'll use this $checklist to populate a drop-down list. I wonder how to pass the parameter. I could just move this part to the form view, but I think it's not a good practice to have this inside a view.
$checkList=Featured::find()
->joinWith('news')
->where(['news.featuredOrder'=>null])
->orderBy('featuredOrder')
->all();
This is my index :
<?php echo \yii\widgets\ListView::widget([
'dataProvider' => $featured,
'itemView'=>'_post',
'options'=>['class'=>'row'],
'itemOptions'=>['class'=>'col-md-4'],
'summary'=>'',
'viewParams'=>['cekList'=>'cekList'],
'pager' => [
'options'=>['class'=>'pagination justify-content-center'],
'linkContainerOptions'=>['class'=>'page-item'],
'linkOptions'=>['class'=>'page-link'],
_post view
div class = "panel panel-default">
<div class = "panel-body">
<h2 class="truncate text-center"><?=Html::a($model->title, ['view', 'id' => $model->id] ) ?> </h2>
<hr>
</div>
<!-- another block of code, but unrelated, so I won't include it -->
This is the view.php file,being rendered if an item's title in the _post above is clicked.
<div class="row justify-content-between">
<div class="col-xs-6">
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Do you want to delete this post?',
'method' => 'post',
],
]) ?>
If an update button is clicked, it will render a form. I want to pass the param to this form.
My Answer is Based On this Query :
$checkList=Featured::find()
->joinWith('news')
->where(['news.featuredOrder'=>null])
->orderBy('featuredOrder')
->all();
If you want to use only above query for drop down there is a two way to do that :
1. Create A method in controller and use array helper method for drop down list add select statement in query
public function checklistDropdown(){
$items = Featured::find()
->joinWith('news')
->where(['news.featuredOrder'=>null])
->orderBy('featuredOrder')
->all();
$items = ArrayHelper::map($items, 'id', 'name');
}
In your index action call this method pass just like you passed model and dataprovider
2. second option is more feasible i think
Create a component helper for generic drop down list add above method in that component and use that component to call the method in you view , you can define that method as STATIC . It will be reusable.
The view that is rendered from the controller has a Pjax begin and end tags:
Pjax::begin([
'id' => 'pjax-questions-list',
'enablePushState' => false,
'clientOptions' => [
'method' => 'get'
],
]);
Inside the Pjax it renders two nested views:
<div class="body">
<?php
echo $this->render('_questions_search', ['model' => $searchModel, ' questionary' => $questionary]);
echo $this->render('_questions_list', ['dataProvider' => $dataProvider, 'model' => $searchModel]);
?>
</div>
Inside the nested view there is a delete question link:
<li>
<a class="waves-effect waves-block" data-pjax="0"
href="<?= Url::to(['question/delete', 'id' => $model->id]) ?>">Delete</a>
</li>
When that link is clicked, the delete action method is called twice. Moreover, this issue is hard to notice when the Pjax is outside of the view that contains the link (i.e. nested views). Because of this issue the redirect after successfull delete doesn't work and instead a 404 not found error is found (tries to delete the same id twice).
How can i fix the double redirect?
You can fix the double redirect by adding the following attribute to your link which is located inside Pjax:
data-pjax="0"
In my case i reused the nested view by deleting the grid view and replacing it with ul with links, and of course forgot to remove the unneeded Pjax in the outer view. After that the issue appeared. It was hard to notice that it was calling the action method twice.
I have 5 tabs on one page. All the tabs have different content, but on one of them i need to have pagination. When click on pagination the page is refreshing and the current opened tab is closed and show by default first tab ... I want when click on pagination, the current tab to be open and the refresh only part with data information.
here is my code:
<?php
Pjax::begin([
'id' => 'w0',
'enablePushState' => true, // I would like the browser to change link
'timeout' => 10000 // Timeout needed
]);
$spec = Specifications::find()->where('active = 1')->orderBy(['sort' => SORT_ASC]);
$count = $spec->count();
$pagination = new Pagination(['totalCount' => $count, 'defaultPageSize' => 20]);
$models = $spec->offset($pagination->offset)
->limit($pagination->limit)
->all();
echo LinkPager::widget([
'pagination' => $pagination,
'hideOnSinglePage' => true,
'prevPageLabel' => 'Предишна',
'nextPageLabel' => 'Следваща'
]);
if ($spec) { ?>
<div class="form-group">
<label>Спецификации</label></br>
<?php
foreach ($models as $singleSpec) {
echo $singleSpec->id." ".$singleSpec->title;
}
?>
</div>
<?php } ?>
<?php Pjax::end() ?>
remove 'id'=>'w0' from Pjax, it is refreshing your page
<?php
echo $form->field($fModel, 'cell_phone')
->widget(\yii\widgets\MaskedInput::className(),['mask' => '(999)999-9999'])
->textInput(['placeholder' => 'Phone'])->label(false);
?>
I have 2 tab with same form with one extra field on second. Issue is that it showing masked input on one tab form and not on second. Anything I am doing wrong. They have same input name/id but FORM ID is different.
You should use another id for second field both for widget and text input. Try this:
<?= $form->field($fModel, 'cell_phone')
->widget(\yii\widgets\MaskedInput::className(), ['options' => ['id' => 'another-id'], 'mask' => '(299)999-9999'])
->textInput(['id' => 'another-id', 'placeholder' => 'Phone'])->label(false);
?>
I added additional menu to function "footer-menu":
function register_theme_menus(){
register_nav_menus(
array(
"header-menu" => __("Header Menu"),
"footer-menu" => __("Footer Menu")
)
);
}
Here is code from footer.php :
<?php
$args1 = array(
"menu" => "footer-menu",
"menu_class" => "nav navbar-nav",
"container" => "false",
"fallback_cb" => "wp_page_menu",
//Process nav menu using our custom nav walker
"walker" => new wp_bootstrap_navwalker()
);
wp_nav_menu($args1);
?>
But when I customizing in dashboard, it still assigned to header menu. Probably it is code issue but I can't find any solution.
enter image description here
Maybe someone had similar issue?
Please can you change "menu" element inside the array to a theme_location.
<?php
$args1 = array(
"theme_location" => "footer-menu",
"menu_class" => "nav navbar-nav",
"container" => "false",
"fallback_cb" => "wp_page_menu",
//Process nav menu using our custom nav walker
"walker" => new wp_bootstrap_navwalker()
);
wp_nav_menu($args1);
?>