Tip on Passing Variable to Raw Custom Grid View Row

Here’s a handy tip on how to pass variables to the custom code in Gridview for raw formatted rows. I’m embarrassed that I’d never seen this before. I’d never the used the syntax and never previously been able to find out how to do this. The key part is “function ($model) use ($custom_variable) {}” where […]

Read More

Yii2 Active Record Hidden Active Form Field or How to Hide an Active Form Field

Here’s a small tip on how to create a hidden field in an active record form, within the model: <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, ‘fullname’)->textInput([‘maxlength’ => true]) ?> /* Example of hiddenInput for an ActiveRecord Active $form->field */ <?= $form->field($model, ‘state’)->hiddenInput([‘value’=> $src->state])->label(false);?> <?= $form->field($model, ‘position_str’)->textInput([‘maxlength’ => true]) ?> <?php ActiveForm::end(); ?>

Read More

Build comma separated string with conjunction

Here’s a comma separated string function which uses the serial comma properly with a conjunction in a list. e.g. apple, berry, ice cream => apple, berry and ice cream. It’s essentially a natural language join: public static function natural_language_join(array $list, $conjunction = ‘and’) { $last = array_pop($list); if ($list) { return implode(‘, ‘, $list) . […]

Read More