Removing the href value in a yii2 link - php

I have a menu i have created in yii2 and i would like to remove the href value to #
This is what i have done
<?php
echo Menu::widget([
'encodeLabels' => false,
'options' => [
'class' => 'topnav menu-left-nest'
],
'items' => [
[
'label' => ThemeNav::link('Manager action, 'fa fa-user'),
'url' => ["#"], //this is the url {{i}}
'options' => ['class' => 'tooltip-tip'],
'items' => [
...items in the dropdown
],
When i check on the inspect element The above url ({{i}}) generates a value eg
But i would like it to remain as
How do i go about this
This is the themenav class function link
public static function link($label, $icon = null) {
$link = null;
if (!empty($icon))
$link .= Html::tag('i','',['class'=>$icon]);
$link .= Html::tag('span', $label, []);
return $link;
}

In Item list spécification, url can be defined as array or string:
array: for predifined route
string: directly the url
url var is used with the function Url::to. More info here:
http://www.yiiframework.com/doc-2.0/yii-helpers-baseurl.html#to()-detail
Manual about widget menu items: http://www.yiiframework.com/doc-2.0/yii-widgets-menu.html#$items-detail

['label' => ThemeNav::link('Manager action, 'fa fa-user'),, 'url' => '#'],

Related

Yii2: googleChart Widget extension in Carousel

I want show graphs in Carousel, the first graph is shown as well as expected see bellow,
But other slinding graphs are different as seen bellow
Note: All graphs are generated from the same databses tables, bellow is the code from my index.php in frontend/view directory
<?php
use backend\models\WaterLevel;
use backend\models\GaugeSite;
use scotthuangzl\googlechart\GoogleChart;
use kv4nt\owlcarousel\OwlCarouselWidget;
$this->title = 'Water Level';
$model = new WaterLevel();
$siteModel = new GaugeSite();
$siteId = $siteModel->getSiteIds();
$counter = count($siteId);
OwlCarouselWidget::begin([
'container' => 'div',
'containerOptions' => [
'id' => 'container-id',
'class' => 'container-class'
],
'pluginOptions' => [
'autoplay' => true,
'autoplayTimeout' => 3000,
'items' => 1,
'loop' => true,
'itemsDesktop' => [1199, 3],
'itemsDesktopSmall' => [979, 3]
]
]);
/**Loop to generate items */
for($i = 0;$i<$counter;$i++){
$id = $siteId[$i];
$data = $model->getLevels($id);
$readings = [['Hour', 'Water Level']];
foreach($data as $value){
array_push($readings,[$value['submition_time'],(int)$value['reading_level']]);
}
echo GoogleChart::widget(
array('visualization' => 'LineChart',
'data' => $readings,
'options' => array('title' => 'Water Level Reading')));
}
OwlCarouselWidget::end();?>
I also have tried to use the GoogleChart::widget in normal bootstrap4 Carousel, but it behaves the same. I appriciate of your idea to take me out from here.

Yii2 Krajee TreeViewInput widget , how to use multiple select?

I have three tables like this :
objects (id , name , tags , ...)
tags (id , name , ...)
object_tags(id , objectID , tagID)
I used krajee treeView input and in my "objects" form I have :
$form->field($model, 'tags')->
widget(\kartik\tree\TreeViewInput::className(),[
'name' => 'kvTreeInput',
'value' => 'false', // preselected values
'query' => Tags::find()->addOrderBy('root, lft')->name,
'headingOptions' => ['label' => 'تگ'],
'rootOptions' => ['label'=>'<i class="fa fa-building"></i>'],
'fontAwesome' => true,
'asDropdown' => true,
'multiple' => true,
'options' => ['disabled' => false]
]);
But I have no idea how should I write the codes in my controller or in my model!!!
In your action you should iterate over the post result
This is just a brief suggestion you must add the code related to your specific need
public function actionYourAction()
{
$post = Yii::$app->request->post();
if (!empty($post)){
$postTags = $post['tags'];
foreach ($postASCCId as $key => $value) {
$modelNew = new YourModel();
$modelNew->tag = $value;
$modelNew->save();
}
}
.....
}

How can I make typeahead show database information in yii2?

I want to make search in my project. I use typeahead but it's not working. This is my code:
<?php
echo '<label class="control-label">Select Repository</label>';
$template = '<div><p class="repo-language">{{no_telepon}}</p>' .
'<p class="repo-name">{{nama}}</p>' .
'<p class="repo-description">{{email}}</p></div>';
echo Typeahead::widget([
'name' => 'twitter_oss',
'options' => ['placeholder' => 'Filter as you type ...'],
'dataset' => [
[
'prefetch' => Penerima::find()->all(),
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
'templates' => [
'notFound' => '<div class="text-danger" style="padding:0 8px">Unable to find repositories for selected query.</div>',
'suggestion' => new JsExpression("Handlebars.compile('{$template}')")
]
]
]
]);
?>
This question was asked long time a go.
I also faced the same problem, but i could figure-out this.
for future reference i add this post.
in your controller
$result = SampleModel::find()
->select('Attribute_name')
->where('name LIKE "%' . $searchParameter .'%"')
->asArray()
->all();
return Json::encode($result);
here you need to get the database value as "associative array", you can get that from using "asArray()".
then as you see return value as Json encode.
in your "View"
<?php
echo Typeahead::widget([
'name' => 'sampleName',
'options' => ['placeholder' => 'Filtering data ...'],
'scrollable' => true,
'pluginOptions' => ['highlight'=>true],
'dataset' => [
[
'remote' => [
'url' => Yii::$app->urlManager->createUrl(['sample/action']) .
'?searchParameter=%QUERY',
'wildcard' => '%QUERY'
],
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('Atribute_name')",
'display' => 'Atribute_name',
'limit' => 10,
],
],
'pluginEvents' => [
'typeahead:select' => 'function(e, s) {
EnableUserDetailsTypeAhead(s);
}',
]
]);
?>
here few things to be consider.
calling to the controller action. you can do that.
Yii::$app->urlManager->createUrl(['sample/action']) .
'?searchParameter=%QUERY',
'wildcard' => '%QUERY'
],
the below lines inside data set must be provide.
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('Atribute_name')",
'display' => 'Atribute_name',
you will get the expected data.
this sample code i have tested and this is working
From the docs:
prefetch: array, configuration for the prefetch options object. Refer documentation for the options you can set for this parameter. The return data must be Json encoded and converted to an associative array of the format [['value' => 'data1'], ['value' => 'data2'],...], where value is the fixed key set in display
You are passing an array of objects instead of an array of key value pairs. You can use asArray to create a list of objects. You will need to change display to the name of the field containing the data:
'prefetch' => Penerima::find()->select('title')->asArray()->all(),

Style text color inside a php function

I am trying to style the check symbol (&#10003) in my member profile tab on a Buddypress site. The tab is created in my functions.php file in my child theme shown in the code below. I want to make the check symbol green and bold. Because this is in PHP and part of a function I don't know how to accomplish this. Any ideas would be appreciated.
add_action('after_setup_theme','kleo_my_custom_tabs');
function kleo_my_custom_tabs()
{
global $bp_tabs;
$bp_tabs = array(); $bp_tabs['verify'] = array(
'type' => 'regular',
'name' => __('Verified &#10003', 'kleo_framework'),
'group' => 'Verify',
'class' => 'regulartab'
);
}
Try this:
'Verified <b style=\'color:#009900;\'>&#10003</b>'
add_action('after_setup_theme','kleo_my_custom_tabs');
function kleo_my_custom_tabs()
{
global $bp_tabs;
$bp_tabs = array(); $bp_tabs['verify'] = array(
'type' => 'regular',
'name' => __('Verified <b style="color:green;">&#10003</b>', 'kleo_framework'),
'group' => 'Verify',
'class' => 'regulartab'
);
}

Zend Form Radio Default Checked

I have the next radio button group:
$enabled = $this->createElement('radio', 'enabled')
->setLabel('Enabled')
->setMultiOptions(array('1'=>'yes', '0'=>'no'))
->setValue($rank_values['enabled'])
->setAttrib('id', 'enabled')
->setAttrib('class', $action . '_enabled')
->setSeparator('');
How can I set a checked radio? Now, when I open my script, there are not selected radio. I want to select 'yes'. How?
Thank you.
it is much more easier :)
$enabled = $this->createElement('radio', 'enabled')
->setLabel('Enabled')
->setMultiOptions(array('1'=>'yes', '0'=>'no'))
->setValue($rank_values['enabled'])
->setAttrib('id', 'enabled')
->setAttrib('class', $action . '_enabled')
->setSeparator('')
->setValue("1");
In case somebody wonders, I'm using the array notation to declare all my elements in my forms and in zend framework 2 to have a default option selected in a radio button you have to add the attribute value and make it have the key of the value_options you want to be selected by default:
// Inside your constructor or init method for your form //
$this->add(
[
'type' => 'Radio',
'name' => 'some_radio',
'options' => [
'value_options' => [
'opt1' => 'Radio option 1',
'opt2' => 'Radio option 2'
]
],
'attributes' => [
'value' => 'opt1' // This set the opt 1 as selected when form is rendered
]
]
);
I found some examples a little confusing because they were using numeric keys in the value options (0, 1) so when I saw 'value' => 1 it wasn't obvious for me that this was the key in the value_options array. Hope this helps someone.
Use this:
->setAttrib("checked","checked")
So that your complete code looks like this:
$enabled = $this->createElement('radio', 'enabled')
->setLabel('Enabled')
->setMultiOptions(array('0'=>'no', '1'=>'yes'))
->setAttrib("checked","checked")
->setValue($rank_values['enabled'])
->setAttrib('id', 'enabled')
->setAttrib('class', $action . '_enabled')
->setSeparator('');
[EDIT] Using setValue:
You can alternatively use this:
->setValue('1')
This will check the option represented by value 1 which is yes.
According to the manual, you would do it this way if you were to use array notation: link to manual
$this->add(
[
'name' => 'someRadioMethod',
'type' => 'radio',
'options' => [
'label' => 'Some descriptive label',
'value_options' => [
[
'value' => '1',
'label' => 'Label for 1',
'selected' => true,
],
[
'value' => '2',
'label' => 'Label for 2',
'selected' => false,
]
],
],
]
);
I found that if you have a filter set then ->setvalue('X') does not work.
I removed ->addFilter('StringToLower')
and added ->setSeparator('')->setValue('N');
Worked a treat
Yeah. I have resolved it using jQuery:
jQuery(document).ready(function(){
var $radios = $('input:radio[name=enabled]');
if($radios.is(':checked') === false) {
$radios.filter('[value=1]').attr('checked', true);
}
});

Categories