Skip to content

Instantly share code, notes, and snippets.

View mdmunir's full-sized avatar

Misbahul D Munir mdmunir

View GitHub Profile
<?php
$model->addRule(['name', 'body'], 'required')
->addRule(['name'],function()use($model){
if(count(array_unique($model->name)) != count($model->name){
$model->addError('name','Name harus unik');
}
});
$('#id_harga, #id_qty').change(function(){
$('#id_total').val($('#id_harga').val()*$('#id_qty').val());
});
@mdmunir
mdmunir / JsBlock.php
Last active August 29, 2015 14:14
Embedd Javascript Block Eith IDE Checking
<?php
namespace app\components;
use yii\web\View;
/**
* JsBlock
*
* @author Misbahul D Munir <[email protected]>
@mdmunir
mdmunir / upload.php
Created February 21, 2015 03:04
Penggunaan yii2-upload-file
<?php
// class User
class User extends ActiveRecord
{
...
public function behaviors()
{
return [
[
'class' => 'mdm\upload\UploadBehavior',
<?php
namespace app\components;
use yii\base\UnknownPropertyException;
use yii\base\UnknownMethodException;
/**
* Prototype
*
@mdmunir
mdmunir / TestAngularController.php
Last active August 29, 2015 14:20
Controller untuk SPA dengan angularjs
<?php
namespace app\controllers;
/**
* Description of TestAngularController
*
* @author Misbahul D Munir <[email protected]>
* @since 1.0
*/
@mdmunir
mdmunir / Kelas.js
Created May 9, 2015 00:46
Inheritance at javascript
Kelas = function() {
var c = function() {
if (this.initialize) {
this.initialize.apply(this, arguments);
}
}
function Extend(dst, src) {
for (var i in src) {
try {
Kelas = function () {
var c = function () {
if (this.initialize) {
this.initialize.apply(this, arguments);
}
}
function Extend(dst, src) {
for (var i in src) {
try {
@mdmunir
mdmunir / SSE.php
Last active August 29, 2015 14:21
<?php
namespace app\components;
/**
* Description of SSE
*
* @author Misbahul D Munir <[email protected]>
* @since 1.0
*/
// di file SiteController.php
public function actionMessage()
{
$sse = new \app\components\SSE();
$counter = rand(1, 10);
$t = time();
//$sse->retry(3000);
while ((time() - $t) < 15) {