{ID} - 3.5.1 Pengenalan
Sebuah controller digunakan untuk mengatur logika dari sebuah bagian di dalam aplikasi anda. Secara umum, controller digunakan untuk mengatur logika dari sebuah single model. Sebagai contoh, jika anda membuat sebuah situs online bakery, anda mungkin mempunyai RecipesController dan IngredientsController yang mengatur recipes anda dan ingredient-nya. Di dalam CakePHP, sebuah controller dinamakan sesuai dengan model yang ditanganinya, dalam bentuk plural (dalam tatanan bahasa Inggris, misal : Car -> Cars, Category -> Categories).
Model Recipe ditangani oleh RecipesController, sedangkan Model Product ditangani oleh ProductsController, begitu seterusnya.
Controller di dalam aplikasi anda adalah class - class yang diturunkan (di extend) dari class AppController dari CakePHP, dimana class ini juga diturunkan dari class Controller inti (utama). Class AppController dapat didefinisikan di /app/app_controller.php dan di dalamnya bisa diletakkan methods yang bisa diakses dari semua controller di dalam aplikasi. Class ini diturunkan dari class Controller yang merupakan standar library CakePHP.
Controller bisa menampung sebanyak mungkin method. Method ini sering juga disebut sebagai actions. Actions adalah method dari controller yang digunakan untuk menampilkan views. Sebuah action adalah sebuah method tunggal dari sebuah controller. Dispatcher CakePHP memanggil actions ketika sebuah permintaan URL sama dengan sebuah action di dalam controller. Dengan mengambil contoh situs online bakery di atas, RecipesController bisa saja memiliki actions view(), share dan search(). Controller tersebut terletak di /app/controllers/recipes_controller.php dan mempunyai isi :
<?php
# /app/controllers/recipes_controller.php
class RecipesController extends AppController {
function view($id) {
//action logic goes here..
}
function share($customer_id, $recipe_id) {
//action logic goes here..
}
function search($query) {
//action logic goes here..
}
}
?>
<?php# /app/controllers/recipes_controller.phpclass RecipesController extends AppController {function view($id) {//action logic goes here..}function share($customer_id, $recipe_id) {//action logic goes here..}function search($query) {//action logic goes here..}}?>
Untuk memenuhi kebutuhan penggunaan controller secara efektif di dalam aplikasi anda, kita akan membahas beberapa core attributes dan method yang disediakan oleh controller dari CakePHP.
{EN} - 3.5.1 Introduction
A controller is used to manage the logic for a part of your application. Most commonly, controllers are used to manage the logic for a single model. For example, if you were building a site for an online bakery, you might have a RecipesController and a IngredientsController managing your recipes and their ingredients. In CakePHP, controllers are named after the model they handle, in plural form.
The Recipe model is handled by the RecipesController, the Product model is handled by the ProductsController, and so on.
Your application's controllers are classes that extend the CakePHP AppController class, which in turn extends a core Controller class. The AppController class can be defined in /app/app_controller.php and it should contain methods that are shared between all of your application’s controllers. It extends the Controller class which is a standard CakePHP library.
Controllers can include any number of methods which are usually referred to as actions. Actions are controller methods used to display views. An action is a single method of a controller. CakePHP’s dispatcher calls actions when an incoming request matches a URL to a controller’s action. Returning to our online bakery example, our RecipesController might contain the view(), share(), and search() actions. The controller would be found in /app/controllers/recipes_controller.php and contain:
<?php
# /app/controllers/recipes_controller.php
class RecipesController extends AppController {
function view($id) {
//action logic goes here..
}
function share($customer_id, $recipe_id) {
//action logic goes here..
}
function search($query) {
//action logic goes here..
}
}
?>
<?php# /app/controllers/recipes_controller.phpclass RecipesController extends AppController {function view($id) {//action logic goes here..}function share($customer_id, $recipe_id) {//action logic goes here..}function search($query) {//action logic goes here..}}?>
In order for you to use a controller effectively in your own application, we’ll cover some of the core attributes and methods provided by CakePHP’s controllers.
Differences
| Lines: 1-12 | Lines: 1-16 | ||
| - | <title>Introduction</title> <p>A controller is used to manage the logic for a part of your application. Most commonly, controllers are used to manage the logic for a single model. For example, if you were building a site for an online bakery, you might have a RecipesController and a IngredientsController managing your recipes and their ingredients. In CakePHP, controllers are named after the model they handle, in plural form. |
+ | <title>Pengenalan</title> <p> Sebuah controller digunakan untuk mengatur logika dari sebuah bagian di dalam aplikasi anda. Secara umum, controller digunakan untuk mengatur logika dari sebuah single model. Sebagai contoh, jika anda membuat sebuah situs online bakery, anda mungkin mempunyai RecipesController dan IngredientsController yang mengatur <em>recipes</em> anda dan <em>ingredient</em>-nya. Di dalam CakePHP, sebuah controller dinamakan sesuai dengan model yang ditanganinya, dalam bentuk plural (dalam tatanan bahasa Inggris, misal : Car -> Cars, Category -> Categories). |
| </p> | </p> | ||
| - | <p>The Recipe model is handled by the RecipesController, the Product model is handled by the ProductsController, and so on. | + | <p> Model Recipe ditangani oleh RecipesController, sedangkan Model Product ditangani oleh ProductsController, begitu seterusnya. |
| </p> | </p> | ||
| - | <p>Your application's controllers are classes that extend the CakePHP AppController class, which in turn extends a core Controller class. The AppController class can be defined in <kbd>/app/app_controller.php</kbd> and it should contain methods that are shared between all of your application’s controllers. It extends the Controller class which is a standard CakePHP library. | + | <p>r /> Controller di dalam aplikasi anda adalah class - class yang diturunkan (di extend) dari class AppController dari CakePHP, dimana class ini juga diturunkan dari class Controller inti (utama). Class AppController dapat didefinisikan di /app/app_controller.php dan di dalamnya bisa diletakkan methods yang bisa diakses dari semua controller di dalam aplikasi. Class ini diturunkan dari class Controller yang merupakan standar library CakePHP. |
| </p> | </p> | ||
| - | <p>Controllers can include any number of methods which are usually referred to as <em>actions</em>. Actions are controller methods used to display views. An action is a single method of a controller. CakePHP’s dispatcher calls actions when an incoming request matches a URL to a controller’s action. Returning to our online bakery example, our RecipesController might contain the <code>view()</code>, <code>share()</code>, and <code>search()</code> actions. The controller would be found in <kbd>/app/controllers/recipes_controller.php</kbd> and contain: | + | <p> Controller bisa menampung sebanyak mungkin method. Method ini sering juga disebut sebagai actions. Actions adalah method dari controller yang digunakan untuk menampilkan views. Sebuah action adalah sebuah method tunggal dari sebuah controller. Dispatcher CakePHP memanggil actions ketika sebuah permintaan URL sama dengan sebuah action di dalam controller. Dengan mengambil contoh situs online bakery di atas, RecipesController bisa saja memiliki actions view(), share dan search(). Controller tersebut terletak di /app/controllers/recipes_controller.php dan mempunyai isi : |
| </p> | </p> | ||
| <pre> | <pre> | ||
| <?php | <?php | ||
| Lines: 28-34 | Lines: 32-38 | ||
| ?> | ?> | ||
| </pre> | </pre> | ||
| <p> | <p> | ||
| - | In order for you to use a controller effectively in your own application, we’ll cover some of the core attributes and methods provided by CakePHP’s controllers. | + | Untuk memenuhi kebutuhan penggunaan controller secara efektif di dalam aplikasi anda, kita akan membahas beberapa <em>core attributes</em> dan method yang disediakan oleh controller dari CakePHP. |
| </p> | </p> | ||
