Showing posts with label yii2 form field without model. Show all posts
Showing posts with label yii2 form field without model. Show all posts

Monday, April 30, 2018

yii2 dropdownlist onchange

Dropdownlist onchange example is showing below. In dropdownlist first attribute is $name ,second attribute should be null, third attribute is $items array and fourth attribute is $options. In this example we are using a callAFunction() on onchange method.

Yii2 Html dropdownlist onchange

use yii\helpers\Html;
Html::beginForm()
Html::dropDownList(
    'username', 
    'null',
    ['1'=>'abc', '2'=>'xyz'],
    ['onchange'=>'callAFunction()']);
 Html::endForm()

//Javascript function
function callAFunction(){
alert('I am here');
}


yii2 dropdownlist without model

Yii2 html dropdownlist

Dropdownlist without model example is showing below. In this section Arrayhelper and Html classes are uses. In dropdownlist the first attribute is $name ,the second attribute is $options and third attribute is $items array.

use yii\helpers\Html;
use yii\helpers\ArrayHelper;

Html::dropDownList('user_id', null,
      ArrayHelper::map(User::find()->all(), 'user_id', 'name'))

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search