1. Go to this page and download the library: Download imliam/yii2-traits library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
useyii\db\ActiveRecord;
useImLiam\Yii2Traits\ActiveRecordHelpers;
classUserextendsActiveRecord{
useActiveRecordHelpers;
}
$user = User::firstOrCreate(['id' => 1], ['username' => 'Admin']);
// Returns user ID 1 if it exists in the database, or creates// a new user with the ID of 1 and username of 'Admin'
useyii\db\ActiveRecord;
useImLiam\Yii2Traits\ActiveRecordHelpers;
classUserextendsActiveRecord{
useActiveRecordHelpers;
}
$user = User::create(['username' => 'Admin']);
// Creates and returns a new user with the username of 'Admin'
useyii\db\ActiveRecord;
useImLiam\Yii2Traits\ActiveRecordHelpers;
classUserextendsActiveRecord{
useActiveRecordHelpers;
}
$user = User::make(['username' => 'Admin']);
// Makes a new user with the username of 'Admin' but does NOT save it to the database
useyii\db\ActiveRecord;
useImLiam\Yii2Traits\ActiveRecordHelpers;
classUserextendsActiveRecord{
useActiveRecordHelpers;
}
User::deleteIfExists(['username' => 'Admin']);
// Deletes all users with the username of 'Admin'
useyii\db\ActiveRecord;
useImLiam\Yii2Traits\ActiveRecordHelpers;
classUserextendsActiveRecord{
useActiveRecordHelpers;
}
$user = User::first();
// Returns the first user in the database
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.