Kamis, 06 April 2017

Membuat dropdown dari Group by DB

<?php echo $this->Form->input('group_id', array('class' => 'form-control', 'label' => false, 'onchange' => 'this.form.submit()')); ?>
$groups = $this->User->Group->find('list');
        $this->set(compact('groups'));

$lokers = $this->User->Loker->find('list',array('conditions'=>array('Loker.status'=>'1')));


public $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
Read More

Rabu, 05 April 2017

Include Model lain dalam cakephp dan Juga Layout

$this->loadModel("Lppm");
$this->layout = 'ajax';
Read More

Jumat, 31 Maret 2017

Rumus segitiga siku2

Rumus-rumus segitiga siku-siku

a. Jika panjang sisi a dan panjang sisi b sudah diketahui ukurannya maka panjang sisi c dapat ditentukan dengan persamaan c2= a2 + b2

b. Jika panjang sisi a dan panjang sisi c sudah diketahui ukurannya maka panjang sisi b dapat ditentukan dengan persamaan b2 = c2 – a2

c. Jika panjang sisi b dan panjang sisi c sudah diketahui ukurannya maka panjang sisi a dapat ditentukan dengan persamaan a2 = c2 – b2

Sedangkan untuk menghitung keliling segitiga siku-siku dapat digunakan rumus :
K = sisi a + sisi b + sisi c, atau
K = sisi + sisi + sisi

Dan untuk luas segitiga siku-siku dapat di gunakan persamaan :
L = ½ x alas x tinggi
L = ½ x a x t
Read More

Minggu, 26 Maret 2017

Cara debugging di laravel/ show query

ada 2 cara debugging simple query

$results = User::where(function($q) use ($request) {
    $q->orWhere('email', 'like', '%john@example.org%');
    $q->orWhere('first_name', 'like', '%John%');
    $q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results)
result
select * from `users` where (`email` like ? or `first_name` like ? or `last_name` like ?)

yang ke dua masuk app routes.php

\DB::listen(function($sql) {
    var_dump($sql);
});

Read More

Selasa, 28 Februari 2017

Cakephp Relasi type inner atau left/right

Cakephp way
class User extends AppModel {
    public $actsAs = array('Containable');
    public $hasMany = array('Message');
}

class Message extends AppModel {
    public $actsAs = array('Containable');
    public $belongsTo = array('User');
}
You need to change the messages.from column to be messages.user_id so that cake can automagically associate the records for you.

Then you can do this from the messages controller:

$this->Message->find('all', array(
    'contain' => array('User')
    'conditions' => array(
        'Message.to' => 4
    ),
    'order' => 'Message.datetime DESC'
));

The (other) CakePHP way
$this->Message->find('all', array(
    'joins' => array(
        array(
            'table' => 'users',
            'alias' => 'UserJoin',
            'type' => 'INNER',
            'conditions' => array(
                'UserJoin.id = Message.from'
            )
        )
    ),
    'conditions' => array(
        'Message.to' => 4
    ),
    'fields' => array('UserJoin.*', 'Message.*'),
    'order' => 'Message.datetime DESC'
));
Using two relationships to the same model

Here is how you can do the first example using two relationships to the same model:

class User extends AppModel {
    public $actsAs = array('Containable');
    public $hasMany = array(
        'MessagesSent' => array(
            'className'  => 'Message',
            'foreignKey' => 'from'
         )
    );
    public $belongsTo = array(
        'MessagesReceived' => array(
            'className'  => 'Message',
            'foreignKey' => 'to'
         )
    );
}

class Message extends AppModel {
    public $actsAs = array('Containable');
    public $belongsTo = array(
        'UserFrom' => array(
            'className'  => 'User',
            'foreignKey' => 'from'
        )
    );
    public $hasMany = array(
        'UserTo' => array(
            'className'  => 'User',
            'foreignKey' => 'to'
        )
    );
}
Now you can do your find call like this:

$this->Message->find('all', array(
    'contain' => array('UserFrom')
    'conditions' => array(
        'Message.to' => 4
    ),
    'order' => 'Message.datetime DESC'
)); 



Read More
Powered By Blogger · Designed By asadly.tk