{NL} - 3.5.1 Introductie

Een controller wordt gebruikt om de logica van je applicatie te beheren. Het meest voorkomende is dat controllers worden gebruikt om de logica te beheren voor één enkel model. Bijvoorbeeld, bij het bouwen van een website voor een online bakkerij kun je een ReceptenController en een IngredientenController hebben om respectievelijk je recepten en hun ingrediënten te beheren. In CakePHP zijn controllers vernoemd naar het model dat ze afhandelen, in meervoudsvorm.

Het Recepten model wordt afgehandeld door de ReceptenController, het Product model wordt afgehandeld door de ProductenController, enzovoorts.

Je applicatie's controllers zijn klassen die de CakePHP AppController uitbreiden, welke op zijn beurt weer de core Controller class uitbreid. De AppController klasse kun je definiëren in /app/app_controller.php en dient alleen methoden te bevatten welke gedeeld worden over alle controllers van je applicatie. Deze breid de Controller klasse uit welke een standaard CakePHP library is.

Controllers kunnen een aantal methoden bevatten waarna over het algemeen als acties naar gerefereerd wordt. Acties zijn controller methoden welke gebruikt worden om views weer te geven. Een actie is één enkele methode van een controller. CakePHP's dispatcher roept de actie aan bij een inkomend verzoek waarvan de URL overeenkomt met een controller's actie. Om terug te komen op ons online bakkerij voorbeeld, onze ReceptenController kan de methoden view(), share() en search() bevatten. De controller zou dan te vinden zijn in /app/controllers/recepten_controller.php en zou bevatten:

    <?php
    
    # /app/controllers/recepten_controller.php

    class ReceptenController extends AppController {
        function view($id)     {
            //actie logica hier..
        }

        function share($klant_id, $recept_id) {
            //actie logica hier..
        }

        function search($query) {
            //actie logica hier..
        }
    }

    ?>
  1. <?php
  2. # /app/controllers/recepten_controller.php
  3. class ReceptenController extends AppController {
  4. function view($id) {
  5. //actie logica hier..
  6. }
  7. function share($klant_id, $recept_id) {
  8. //actie logica hier..
  9. }
  10. function search($query) {
  11. //actie logica hier..
  12. }
  13. }
  14. ?>

Om een controller effectief in je applicatie te kunnen gebruiken zullen we nu wat kern attributen en methoden bespreken welke te vinden zijn in CakePHP's controllers.

{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..
        }
    }

    ?>
  1. <?php
  2. # /app/controllers/recipes_controller.php
  3. class RecipesController extends AppController {
  4. function view($id) {
  5. //action logic goes here..
  6. }
  7. function share($customer_id, $recipe_id) {
  8. //action logic goes here..
  9. }
  10. function search($query) {
  11. //action logic goes here..
  12. }
  13. }
  14. ?>

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-34Lines: 1-37
-<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>Introductie</title>
<p>
Een
controller wordt gebruikt om de logica van je applicatie te beheren. Het meest voorkomende is dat controllers worden gebruikt om de logica te beheren voor één enkel model. Bijvoorbeeld, bij het bouwen van een website voor een online bakkerij kun je een ReceptenController en een IngredientenController hebben om respectievelijk je recepten en hun ingrediënten te beheren. In CakePHP zijn controllers vernoemd naar het model dat ze afhandelen, in meervoudsvorm.
 </p> </p>
-<p>The Recipe model is handled by the RecipesController, the Product model is handled by the ProductsController, and so on. +<p>
H
et Recepten model wordt afgehandeld door de ReceptenController, het Product model wordt afgehandeld door de ProductenController, enzovoorts.
 </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 /> Je applicatie's controllers zijn klassen die de CakePHP AppController uitbreiden, welke op zijn beurt weer de core Controller class uitbreid. De AppController klasse kun je definiëren in /app/app_controller.php en dient alleen methoden te bevatten welke gedeeld worden over alle controllers van je applicatie. Deze breid de Controller klasse uit welke een standaard CakePHP <em>library</em> is.
 </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. CakePHPs dispatcher calls actions when an incoming request matches a URL to a controllers action. Returning to our online bakery example, our RecipesController might contain the &lt;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>
Controllers kunnen een aantal methoden bevatten waarna over het algemeen als <em>acties</em> naar gerefereerd wordt. Acties zijn controller methoden welke gebruikt worden om views weer te geven. Een actie is één enkele methode van een controller. CakePHP's dispatcher roept de actie aan bij een inkomend verzoek waarvan de URL overeenkomt met een controller's actie. Om terug te komen op ons online bakkerij voorbeeld, onze ReceptenController kan de methoden view(), share() en search() bevatten. De controller zou dan te vinden zijn in /app/controllers/recepten_controller.php en zou bevatten:
 </p> </p>
 <pre> <pre>
  &lt;?php  &lt;?php
   
- # /app/controllers/recipes_controller.php + # /app/controllers/recepten_controller.php
- class RecipesController extends AppController { + class ReceptenController extends AppController {
  function view($id) {  function view($id) {
- //action logic goes here.. + //actie logica hier..
  }  }
- function share($customer_id, $recipe_id) {
//action logic goes here..
+ function share($klant_id, $recept_id) {
//actie logica hier..
  }  }
  function search($query) {  function search($query) {
- //action logic goes here.. + //actie logica hier..
  }  }
  }  }
  ?&gt;  ?&gt;
 </pre> </pre>
 <p> <p>
- In order for you to use a controller effectively in your own application, well cover some of the core attributes and methods provided by CakePHPs controllers. +Om een controller effectief in je applicatie te kunnen gebruiken zullen we nu wat kern attributen en methoden bespreken welke te vinden zijn in CakePHP's controllers.
 </p> </p>