-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCheat sheet - ActiveForm.php
40 lines (34 loc) · 1.81 KB
/
Cheat sheet - ActiveForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/*
===============================================================================================================
_form.php
===============================================================================================================
$editAttribs below is an array of attributes (from safeAttributes()) that user is allowed to edit.
$viewAttribs below is an array of attributes that user is allowed to see.
*/
// Drop-down list with model
if (in_array('cvpu_customerID', $viewAttribs)) {
echo $form->field($model, 'cvpu_customerID')
->dropDownList(ArrayHelper::map(Customer::findOfUser(), 'customerID', 'cust_name'), ['disabled' => !in_array('cvpu_customerID', $editAttribs) ])
->hint($hints['cvpu_customerID']);
}
// Drop-down list with model - with customization
if (in_array('cvpu_contacttypeID', $viewAttribs)) {
echo $form->field($model, 'cvpu_contacttypeID')
->dropDownList(ArrayHelper::map(ContactType::findMine()->andWhere(['conty_customerID' => $model->cvpu_customerID])->all(), 'contacttypeID', 'conty_name'), ['disabled' => !in_array('cvpu_contacttypeID', $editAttribs) ])
->hint($hints['cvpu_contacttypeID']);
}
// Drop-down list with allowedValues() from model
if (in_array('cust_type', $viewAttribs)) {
echo $form->field($model, 'cust_type')
->dropDownList(Customer::allowedValues('cust_type'), ['disabled' => !in_array('cust_type', $editAttribs) ])
->hint($hints['cust_type']);
}
/*
===============================================================================================================
_search.php
===============================================================================================================
*/
// Add empty entry in beginning of array
echo $form->field($model, 'cvpu_customerID')
->dropDownList(['' => ''] + ArrayHelper::map(Customer::findOfUser(), 'customerID', 'cust_name'));