Running Both WordPress and Yii2

Running Yii2 and WordPress on the Same Server A lot of people around the web seem rightfully confused about running both WordPress and Yii2 together. In other words, you’re running a Yii server with your application on yourdomain.com but wish to run WordPress at yourdomain.com/blog! How do you do it? After I launched Meeting Planner, […]

Read More

Github: How to revert multiple commits

If you haven’t generated dependencies for other collaborators with your code and you wish to back up several commits, this should work just fine: $ git reset –hard HEAD is now at xxxxxxx Description $ git push -f Total 0 (delta 0), reused 0 (delta 0) To https://github.com/username/repository.git + 725b5eba…12739094 master -> master (forced update)

Read More

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

Yii2 Gridview Filtering with Tabs

If you’re using Yii2 Gridview with tabs and notice that when the user filters the results, posting the page goes to the wrong tab. This solution worked great for me: $(document).ready(function() { $(‘a[data-toggle=\”tab\”]’).on(‘show.bs.tab’, function (e) { localStorage.setItem(‘lastTab’, $(this).attr(‘href’)); }); var lastTab = localStorage.getItem(‘lastTab’); if (lastTab) { $(‘[href=\”‘ + lastTab + ‘\”]’).tab(‘show’); } }); via Maintain […]

Read More

Important for Yii Developers to Update Composer Asset Plugin

Per this note at YiiFeed, Yii developers need to update our composer asset plugins: Bower has changed their registry URL some time ago and has now announced to deprecate the old URL. Old registry will be disabled next Wednesday. In order for your work not to be affected make sure to update your composer asset plugin […]

Read More

Jeff Reifman Interviewed by Cloudways

Recently, cloud hosting provider Cloudways interviewed Yii2x founder Jeff Reifman. Cloudways asked about Jeff’s development as a PHP programmer and what he appreciates most about the Yii Framework. There’s also discussion about how he builds features for scheduling meetings in his startup, Meeting Planner: Recently, I gave a meetup presentation on how I built the […]

Read More

Viewing the Native SQL Generated by Yii Queries

Here’s how to see the native SQL or raw SQL generated by Yii queries. The easy way is to open the debug area and click on the DB tab. Recently, I was debugging complex SQL queries for background tasks and wanted to see the raw SQL generated. The debugger isn’t as easily available. I used […]

Read More