[Cakephp] Method yang sering dipakai di Cakephp


Deskripsi
       Berikut adalah fungsi-fungsi yang sering saya pakai di cakephp pada bagian controller dan view.

How to
In Controller :
* Router::url(array('controller'=>'main','action'=>'logout'), true); // change page
* $this->render(false / true); // execute controller, but disable view
* $this->layout = layout_name / false; // use layout
* $this->theme = theme_name / false; // use theme
* $this->redirect(array('controller'=>'mycontroller','action'=>'myaction')); // redirect page
* $this->request->is('ajax') // check if request is ajax
* $this->request->is('post') // check if request is post
* $this->set('new_variable','value'); // create var to view
* $this->data / $this->request->data
* $this->Session->delete/read/write('mysession')
* $this->Auth->deny('*'); //disable all action , current controller
* $this->Auth->allow('login','not_supported'); //action only , current controller
* Debug($variable)
* App:import('Vendor','tcpdf/tcpdf'); // use tcpdf class

simpan record 1 field

$this->MODEL->id=$id;
$this->MODEL->saveField('FIELD','value');




In View :

$this->Html->meta('icon',$this->Html->url('/favicon.ico'));
$this->Html->css('yourcss');
$this->Html->css('jquery-ui-1.9.0.custom');

membuat link :
<?php echo $this->Html->link('Edit',array('controller'=>'xxx','action'=>'zzz','escape'=>false)) ?>

menambahkan image :
<?php echo $this->Html->image('loading.gif') ?>

membuat button link :
<?php echo $this->Form->button('Logout', array('onclick' => "location.href='/myapp/main/index'")) ?>

membuat button link untuk akses file di folder webroot/files/report/xxx  :
<form method="GET" Action="<?php echo $this->webroot.'files/reports/'.$myuser.'.xlsx'?>">
            <input TYPE="submit" VALUE="Download Report">
</form>

membuat form di view
$this->Form->create('MODEL',array('controller'=>'','action'=>''))
$this->Form->input('field',array(attribute))
$this->Form->submit('value')
$this->form->end()

//table ajax pagination
<?php $this->Paginator->options(array(
'update' => "#location_div_table",
'evalScripts' => true,
'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),
));
?>

// for pagination
 <th colspan="7" class="tPagination">
                        <div id="paging">
                        <?php
                        echo $this->Paginator->prev('&laquo; Sebelumnya', array('escape' => FALSE));
                        echo ' |';
                        echo $this->Paginator->numbers(array('separator' => false));
                        echo '| ';
                        echo $this->Paginator->next('Selanjutnya &raquo; ', array('escape' => FALSE));
                        ?>
                        </div>
   </th>

//close tag
<?php echo $this->Js->writeBuffer(); ?>

*Note : Update 19/03/2014

2 comments

ada yang ketinggalan bro ... debug($this->request->data); hehehe

Reply

oh iya debugnya lupa kwkwkwwkkw

klo $this->request->data udah ada gan (di controller)

tq dah nambahin :D

Reply

Post a Comment

Harap gunakan bahasa yang baik dan sopan, terima kasih