Skip to content

Instantly share code, notes, and snippets.

$ ../vendor/bin/codecept build

Building Actor classes for suites: functional, unit
bedezign\yii2\audit\tests\FunctionalTester includes modules: Yii2, tests\codeception\_support\FixtureHelper, tests\codeception\_support\MailHelper
FunctionalTester.php generated successfully. 54 methods added
bedezign\yii2\audit\tests\UnitTester includes modules: Asserts, tests\codeception\_support\CodeHelper
UnitTester.php generated successfully. 19 methods added
root@test:/vagrant/git/yii2-audit/tests# ../vendor/bin/codecept run
Codeception PHP Testing Framework v2.0.14
Powered by PHPUnit 4.6.10 by Sebastian Bergmann and contributors.
Bedezign\yii2\audit\tests.functional Tests (1) ----------------------------------------------------------------------
Ensure that home page works (HomeCept) Error
---------------------------------------------------------------------------------------------------------------------
Bedezign\yii2\audit\tests.unit Tests (0) ----
---------------------------------------------
@cornernote
cornernote / README.md
Last active August 29, 2015 14:23
Yii2 batchInsert

I am using batchInsert to insert bulk data, but its inserting in the wrong order in php5.4 (php5.5+ is fine).

I found the reason, but dont understand where Yii2 is doing this...

I am looking at the source for batchInsert (https://github.com/yiisoft/yii2/blob/master/framework/db/QueryBuilder.php#L181), and I dont understand how it's doing the unions.. i cant see code for that anywhere

PHP 5.4

INSERT INTO `audit_trail` (`audit_id`, `user_id`, `old_value`, `new_value`, `action`, `model`, `model_id`, `field`, `stamp`) 
SELECT NULL, NULL, '', '4', 'CREATE', 'tests\models\Post', '4', 'id', '2015-06-22 15:02:38' 
@cornernote
cornernote / AuditController.php
Created June 22, 2015 10:11
email errors in yii2-audit
<?php
namespace bedezign\yii2\audit\commands;
use bedezign\yii2\audit\models\AuditEntry;
use bedezign\yii2\audit\models\AuditError;
use Yii;
use yii\helpers\Html;
/**
@cornernote
cornernote / select2.html
Created June 15, 2015 00:41
select2 with free-text
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<title>Select 2</title>
</head>
<body>
@cornernote
cornernote / README.md
Created June 4, 2015 12:38
How to use PsySH with a Yii2 application

Using PsySH (GitHub) as the Yii2 shell

  • Issue the following commands from the command line in your Yii application directory:
    • chmod +x psyii
    • mkdir extensions/yiishell
    • wget -O extensions/yiishell/psysh psysh.org/psysh
    • chmod +x extensions/yiishell/psysh
  • Copy the file init.php below to psysh/init.php and update any paths to work with your application configuration
  • Copy the file config.php below to psysh/config.php. Change or add to the config array with the options you'd like to use (available options)
  • Now you can start PsySH with the command ./psyii psysh/init.php --config psysh/config.php
@cornernote
cornernote / Model.php
Last active August 29, 2015 14:22
orOnCondition relation
<?php
class Job extends \yii\db\ActiveRecord
{
public function getAuditFields()
{
$link = [];
return $this->hasMany(AuditField::className(), $link)
->orOnCondition([
'audit_field.model_id' => $this->job_id,
@cornernote
cornernote / README.md
Last active October 14, 2015 14:43
code generator config

Using Giiant with Providers

The following code should be added to the bootstrap of your yii application. If you would like to keep it in it's own file (recommended) create a config/giiant.php, then include it from your config/bootstrap.php.

DateTimeProvider

Use a DateTimePicker for the scheduled_at field:

@cornernote
cornernote / DateTimeProvider.php
Created May 26, 2015 15:17
hacky DateTimeProvider to add spaces
<?php
namespace app\gii\giiant\providers;
class DateTimeProvider extends \schmunk42\giiant\crud\providers\DateTimeProvider
{
public function activeField($attribute)
{
$data = parent::activeField($attribute);
<?php
namespace app\components;
class ActiveRecord extends \yii\db\ActiveRecord
{
public function safeAttributes()
{