{ID} - 2.1.1 Ekstensi-ekstensi untuk Controller
Komponen adalah sebuah class bantu dalam logik controller. Jika Anda mempunyai beberapa logik yang ingin digunakan juga oleh controller (atau aplikasi) lain, maka penggunaan komponen sangat tepat. Misal, class inti dari EmailComponent membuat tugas menulis dan mengirim email menjadi lebih mudah. Daripada menulis sebuah method dalam satu controller untuk mengeksekusi logik ini, Anda dapat mempaket logik tersebut sehingga dapat digunakan secara bersama.
Controller juga bisa dipadankan dengan callback. Callback dapat digunakan saat Anda ingin menyisipkan beberapa logik diantara operasi inti CakePHP. Callback yang tersedia diantaranya:
- beforeFilter(), dieksekusi sebelum logik action controller
- beforeRender(), dieksekusi setelah logik controller, tapi sebelum view dirender
- afterFilter(), dieksekusi setelah semua logik controller, termasuk render view. Mungkin tidak ada perbedaan antara afterRender() dan afterFilter() kecuali Anda secara manual membuat prmanggilan ke render() di action controller dan memasukkan beberapa logik setelah pemanggilan tersebut.
{EN} - 2.1.1 Controller Extensions ("Components")
A Component is a class that aids in controller logic. If you have some logic you want to share between controllers (or applications), a component is usually a good fit. As an example, the core EmailComponent class makes creating and sending emails a snap. Rather than writing a controller method in a single controller that performs this logic, you can package the logic so it can be shared.
Controllers are also fitted with callbacks. These callbacks are available for your use, just in case you need to insert some logic between CakePHP’s core operations. Callbacks available include:
beforeFilter(), executed before any controller action logicbeforeRender(), executed after controller logic, but before the view is renderedafterFilter(), executed after all controller logic, including the view render. There may be no difference betweenafterRender()andafterFilter()unless you’ve manually made a call torender()in your controller action and have included some logic after that call.
Differences
| Lines: 1-8 | Lines: 1-8 | ||
| - | <title>Controller Extensions ("Components")</title> <p>A Component is a class that aids in controller logic. If you have some logic you want to share between controllers (or applications), a component is usually a good fit. As an example, the core EmailComponent class makes creating and sending emails a snap. Rather than writing a controller method in a single controller that performs this logic, you can package the logic so it can be shared.</p> <p>Controllers are also fitted with callbacks. These callbacks are available for your use, just in case you need to insert some logic between CakePHP’s core operations. Callbacks available include:</p> |
+ | <title>Ekstensi-ekstensi untuk Controller</title> <p>Komponen adalah sebuah <em>class</em> bantu dalam logik <em>controller</em>. Jika Anda mempunyai beberapa logik yang ingin digunakan juga oleh controller (atau aplikasi) lain, maka penggunaan komponen sangat tepat. Misal, <em>class</em> inti dari EmailComponent membuat tugas menulis dan mengirim email menjadi lebih mudah. Daripada menulis sebuah <em>method</em> dalam satu <em>controller</em> untuk mengeksekusi logik ini, Anda dapat mempaket logik tersebut sehingga dapat digunakan secara bersama.</p> <p>Controller juga bisa dipadankan dengan <em>callback</em>. Callback dapat digunakan saat Anda ingin menyisipkan beberapa logik diantara operasi inti CakePHP. Callback yang tersedia diantaranya:</p> |
| <ul> | <ul> | ||
| - | <li><code>beforeFilter()</code>, executed before any controller action logic</li> <li><code>beforeRender()</code>, executed after controller logic, but before the view is rendered</li> <li><code>afterFilter()</code>, executed after all controller logic, including the view render. There may be no difference between <code>afterRender()</code> and <code>afterFilter()</code> unless you’ve manually made a call to <code>render()</code> in your controller action and have included some logic after that call.</li> |
+ | <li>beforeFilter(), dieksekusi sebelum logik <em>action controller</em></li> <li>beforeRender(), dieksekusi setelah logik controller, tapi sebelum <em>view</em> di<em>render</em></li> <li>afterFilter(), dieksekusi setelah semua logik <em>controller</em>, termasuk <em>render view</em>. Mungkin tidak ada perbedaan antara afterRender() dan afterFilter() kecuali Anda secara manual membuat prmanggilan ke render() di <em>action controller</em> dan memasukkan beberapa logik setelah pemanggilan tersebut.</li> |
| </ul> | </ul> | ||
