Part three of my Building Your Startup series is available now at Tuts+, its focus is HTML5 Geolocation, Google Places and Google Maps. In this part, we’re going to build some of the underlying infrastructure for the concept of Places where people can schedule meetings. We’ll cover the basics of working with Places, building on our […]
Monthly Archives: February 2015
The Dual Listbox Widget
This is a really beautiful and useful Yii2 widget – the Dual List box based on the DualListBox JQuery widget. Great demo here. Here’s a write up with more detail at Yii: the Yii2 Dual-List Box.
Setting the State of the Switch Input Widget Radio Button
The Krajee Switch Input widget for Yii2 based on Bootstrap Switch is great. I’ll write more about it in the near future. However, I had one major problem with a gap in the documentation – others seem to have been confused as well. When you’re using the widget in SwitchInput::RADIO mode, it’s not well documented […]
Programming With Yii2: Exploring MVC, Forms and Layouts
As my Programming With Yii2 series continues at Tuts+, part two explores MVC, Forms and Layouts: “This tutorial will cover some of Yii’s more basic concepts related to its implementation of the MVC framework: Models, Views and Controllers. We’ll also explore layouts and customization of navigation menus and Bootstrap elements. For these examples, we’ll imagine we’re building a […]
How to Display Form Errors (the ErrorSummary)
Let’s say you’re using a validator that doesn’t correspond to a specific field and you want to display it on the form. For example, I’m using the compare validator and wish the error summary to appear on the create form. [php] <?php use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model frontend\models\Participant */ […]
How to Use the Yii2 Compare Validation
Here’s an example of how to use the Yii2 compare validator. The rules go in your model e.g. app/models/Participant.php. In this example, I’m ensuring that the participant_id and the invited_by id are not the same. I don’t want someone to be able to invite themselves. [php] public function rules() { return [ [‘participant_id’, ‘compare’,’compareAttribute’=>’invited_by’,’operator’=>’!=’,’message’=>’You cannot invite […]
How to Count ActiveDataProvider Items
Here’s how to create an ActiveDataProvider in Yii2 and get a count of records: [php] use yii\data\ActiveDataProvider; $participantProvider = new ActiveDataProvider([ ‘query’ => Participant::find()->where([‘meeting_id’=>$id]), ]); echo $participantProvider->getCount(); [/php]
Check if a record exists using ActiveRecord
In Yii2, if you’d like to check if a record exists in a table, use the following code: [php] Customer::find()->where( [ ’email’ => ‘jeff@yii2x.com’ ] )->exists(); [/php]