Yii's zii.widgets.CMenu - can it be a pop-up menu? - yii

Hi I'm using the test code from http://www.yiiframework.com/doc/api/1.1/CMenu
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
// Important: you need to specify url as 'controller/action',
// not just as 'controller' even if default acion is used.
array('label'=>'Home', 'url'=>array('site/index')),
// 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
)),
array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
),
));
Other test code such as zii.widgets.jui.CJuiAutoComplete and zii.widgets.jui.CJuiDraggable work fine in my Yii view...
The CMenu code snippet just shows the links as a hierarchical list.
When using a div with an id of mainmenu things seem to improve a bit... then I tried using a lot of nested arrays:
http://sky-walker.net/temp/test/yii/testnews/index.php?r=site/test
It supports array nesting of 5+ levels deep...
But if I highlight/select it all (to display the white menu links) it doesn't display the hierarchy nicely...
I was wondering if it could be a popup menu that gradually shows children if the parents are hovered over?
I also tried disabling the div with id of mainmenu from the layout's main.php.

ok, after seeing what you have, follow my example:
<div id="mainmenu">
<?php
$this->widget('zii.widgets.CMenu', array(
'items' => array(
array('label' => 'linkbook', 'url' => array('/site/index')),
array('label' => 'About', 'url' => array('/site/page', 'view' => 'about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
array('label' => 'Suggest Website', 'url' => array('/websiteSuggest/index'),'visible' => !Yii::app()->user->isGuest),
array('label' => 'Servers', 'url' => array('/server/index'),'visible' => !Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->loginUrl, 'label' => Yii::app()->getModule('user')->t("Login"), 'visible' => Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->registrationUrl, 'label' => Yii::app()->getModule('user')->t("Register"), 'visible' => Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->profileUrl, 'label' => Yii::app()->getModule('user')->t("Profile"), 'visible' => !Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->logoutUrl, 'label' => Yii::app()->getModule('user')->t("Logout") . ' (' . Yii::app()->user->name . ')', 'visible' => !Yii::app()->user->isGuest),
),
));
?>
</div><!-- mainmenu -->
<br/>
<div id="mainmenu">
<?php
$this->widget('zii.widgets.CMenu', array(
'items' => array(
array('label' => 'Website', 'url' => array('/website/index'), 'visible' => !Yii::app()->user->isGuest),
array('label' => 'Url', 'url' => array('/url/index'), 'visible' => !Yii::app()->user->isGuest),
array('label' => 'Pattern Url', 'url' => array('/patternUrl/index'), 'visible' => !Yii::app()->user->isGuest),
),
));
?>
</div>

I'm using the MbMenu Yii extension now...
http://www.yiiframework.com/extension/mbmenu
It is very easy to install and use and it seems the input array from CMenu can be reused with it (as well as the CssMenu Yii extension)...
It is at the bottom of:
http://sky-walker.net/temp/test/yii/testnews/index.php?r=site/test

Related

hook with form Prestashop 1.7

guys (and ladies)
I like to ask you how to build the forms (formbuilder) in Prestashop 1.7 for the current 2020 year.
I created module with classes and hooks, but I can't find the info on how to create forms via "classes" and "controllers".
I'd happy to have something like this:
What have already done:
created custom module
created custom hook
custom .tpl from /module/templates/front/custom.tpl is added to the hook and displays data correctly.
Using form builder in your .php file (or controller)
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Live mode'),
'name' => 'TESTONE_LIVE_MODE',
'is_bool' => true,
'desc' => $this->l('Use this module in live mode'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'TESTONE_ACCOUNT_EMAIL',
'label' => $this->l('Email'),
),
array(
'type' => 'password',
'name' => 'TESTONE_ACCOUNT_PASSWORD',
'label' => $this->l('Password'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}

dependent dropdownlistGroup Yii Booster

I just learning Yiibooster recently and stuck with this..
I have a dependent dropdownlistgroup using yii booster with ajax so kelas data will be generated after matkul selected. It works fine if i using dropdownlist from yii but i want a nice form using Yiibooster form.
<?php
echo $form->dropDownListGroup(
$model,
'matkul',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $matkullist,
'htmlOptions' => array('multiple' => false),
),
'prompt'=>'Select',
array(
'ajax'=> array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Kp/Getkelas'), //url to call.
'update'=>'#'.CHtml::activeId($model,'kelas'), //selector to update
)
)
)
); ?>
<?php echo $form->dropDownListGroup(
$model,
'kelas',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array('multiple' => false),
)
)
);?>
The problem is the ajax does not work when i use dropdownlistgroup, when i test it with normal dropdownlist like below code its work normal, sorry for my english.
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Kp/Getkelas'), //url to call.
'update'=>'#city_id', //selector to update
)));
echo CHtml::dropDownList('city_id','', array());
I'm not hear about the function dropdownListGroup.
using Yiibooster, you can add the dropdown as,
$this->widget(
'booster.widgets.TbSelect2',
array(
'asDropDownList' => false,
'name' => 'clevertech',
'options' => array(
'tags' => array('clever', 'is', 'better', 'clevertech'),
'placeholder' => 'type clever, or is, or just type!',
'width' => '40%',
'tokenSeparators' => array(',', ' ')
)
)
);
ref link : http://yiibooster.clevertech.biz/widgets/forms_inputs/view/select2.html
You should put ajax options in widgetOptions -> htmlOptions -> ajax
$form->dropDownListGroup($model, 'beer', array(
'widgetOptions' => array(
'data' => CHtml::listData(Beer::model()->findAll(), 'id', 'name'),
'htmlOptions' => array(
'ajax' => array(
'type' => 'POST',
'url' => Yii::app()->createUrl('/beer'),
'update' => '#beer',
)
),
)
);
not most efficient solution but it works,
looking the html at the end, we have
<div class="form-group">
<?php echo $form->labelEx($model,'matkul',array('class' => 'col-sm-3 control-label')); ?>
<div class="col-sm-5 col-sm-9">
<?php echo $form->dropDownList($model,'matkul',$matkullist รณ array(),
array('class' => 'form-control','ajax'=>array('type'=>'POST','url'=>CController::createUrl('Kp/Getkelas'),'update'=>'#'.CHtml::activeId($model,'kelas')),'empty'=>'Select')); ?>
<?php echo $form->error($model,'matkul'); ?>
</div>
</div>
important is that 'class' put the html class, 'class' => 'col-sm-3 control-label' and 'class' => 'form-control', for dropDownList

Yii ESelect2 extension show preselected valued

i want to show already selected values in tags of ESelected extension but unable to find any solution my code in update form in view is
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));
if i add tags fields in option of Eselect it changes the behaviour and stop working i add tags in options like this
'tags' => Coupon::getCategories_old(),
Any suggestion will be helpfull thanks in advance
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'value'=> array(91,95),
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));

YiiBooster Navbar target _blank

I am using the navbar of the extension Yiibooster, but I am having problems with a subitem of the menu, I need to go to a new tab, but I can't make it.
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => '<img src ="' . Yii::app()->request->baseUrl . '/images/FAVICON.png" />Inicio',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array('label' => 'Listado de Activos', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'itemOptions' => array('target' => '_blank')),
)),
If you want go to blank only in one item of the menu, this is the best option:
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array(
'label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'linkOptions' => array(
'target' => '_blank'
),
),
),
),
)
Yii CMenu docs: http://www.yiiframework.com/doc/api/1.1/CMenu#items-detail
add class=>'bootstrap.widgets.TbMenu' like
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'submenuOptions' => array('target' => '_blank'),
'items' => array(
array('label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
),
)
)
You need to use $brandOptions:
NavBar::begin([
'brandLabel' => 'Label text',
'brandUrl' => '/'.Yii::$app->homeUrl,
'brandOptions' => [
'target'=>'_blank'
],
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);

Yiibooster modal from navbar

I need to call my modal widget from a navbar using Yiibooster
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Inicio',
'fixed' => false,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => '#', 'active' => true),
array('label' => 'Filtro', 'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/create'),
)
)
)
)
));?>
htmlOptions doesnt work there, what can i do?
Use linkOptions instead of htmlOptions
...
array('label' => 'Filtro', 'linkOptions' => array('data-toggle' => 'modal','data-target' => '#myModal')),
...
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Zona Franca',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Inicio', 'url' => Yii::app()->baseUrl),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfArrendatarios/create'),
)),
array(
'class' => 'bootstrap.widgets.TbMenu',
'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
'items' => array(
array('label' => 'Filtro', 'url' => '#myModal'),
)),
)
)
)
;?>
There you have the answer :D