diff --git a/en/developers/understanding-cakephp.rst b/en/developers/understanding-cakephp.rst index 4525008..d9d1313 100644 --- a/en/developers/understanding-cakephp.rst +++ b/en/developers/understanding-cakephp.rst @@ -1,13 +1,4 @@ Understanding CakePHP ##################### -Please visit http://book.cakephp.org for official documentation. - -.. toctree:: - - understanding-cakephp/controllers - understanding-cakephp/components - understanding-cakephp/models - understanding-cakephp/behaviors - understanding-cakephp/views - understanding-cakephp/helpers \ No newline at end of file +Please visit http://book.cakephp.org for official documentation. \ No newline at end of file diff --git a/en/developers/understanding-cakephp/behaviors.rst b/en/developers/understanding-cakephp/behaviors.rst deleted file mode 100644 index 8939db2..0000000 --- a/en/developers/understanding-cakephp/behaviors.rst +++ /dev/null @@ -1,65 +0,0 @@ -Behaviors -######### - -Read the CakePHP docs on Behaviors: http://book.cakephp.org/2.0/en/models/behaviors.html. - -Model behaviors are a way to organize some of the functionality defined in CakePHP models. They allow us to separate logic that may not be directly related to a model, but needs to be there. By providing a simple yet powerful way to extend models, behaviors allow us to attach functionality to models by defining a simple class variable. That's how behaviors allow models to get rid of all the extra weight that might not be part of the business contract they are modeling, or that is also needed in different models and can then be extrapolated. - -As an example, consider a model that gives us access to a database table which stores structural information about a tree. Removing, adding, and migrating nodes in the tree is not as simple as deleting, inserting, and editing rows in the table. Many records may need to be updated as things move around. Rather than creating those tree-manipulation methods on a per model basis (for every model that needs that functionality), we could simply tell our model to use the TreeBehavior, or in more formal terms, we tell our model to behave as a Tree. This is known as attaching a behavior to a model. With just one line of code, our CakePHP model takes on a whole new set of methods that allow it to interact with the underlying structure. - -Code -#### - -If your Behavior's name is Example, it would be found at `/app/Model/Behavior/ExampleBehavior.php`:: - - settings[$Model->alias] = $config; - } - - public function beforeFind(&$Model, $query) { - return $query; - } - - public function afterFind(&$Model, $results, $primary) { - - } - - public function beforeDelete(&$Model, $cascade = true) { - return true; - } - - public function afterDelete(&$Model) { - - } - - public function beforeValidate(&$Model) { - return true; - } - - } - -Plugin Behaviors ----------------- - -If it is Example plugin's behavior, it would be found at `/app/Plugin/Example/Model/Behavior/ExampleBehavior.php`. - -Using Behaviors in Models -========================= - -:: - - array( // 'Example.Example' if it is from Example plugin - 'config1' => 'value here', - 'config2' => 'value here', - ), - ); - - } - diff --git a/en/developers/understanding-cakephp/components.rst b/en/developers/understanding-cakephp/components.rst deleted file mode 100644 index 995346e..0000000 --- a/en/developers/understanding-cakephp/components.rst +++ /dev/null @@ -1,47 +0,0 @@ -Components -########## - -Read the CakePHP docs on Components: http://book.cakephp.org/2.0/en/controllers/components.html. - -What is a Component? -==================== - -Components are packages of logic that are shared between controllers. If you find yourself wanting to copy and paste things between controllers, you might consider wrapping some functionality in a component. - -Code -==== - -Assuming you want to create an Example component, it would be found at `/app/Controller/Component/ExampleComponent.php`:: - - Example->myMethod(); - } - - } \ No newline at end of file diff --git a/en/developers/understanding-cakephp/controllers.rst b/en/developers/understanding-cakephp/controllers.rst deleted file mode 100644 index 4612d19..0000000 --- a/en/developers/understanding-cakephp/controllers.rst +++ /dev/null @@ -1,50 +0,0 @@ -Controllers -########### - -Read the CakePHP docs on Controllers: http://book.cakephp.org/2.0/en/controllers.html. - -What is a Controller? -===================== - -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, which are part of the CakePHP library. The AppController class can be defined in `/app/Controller/AppController.php` and it should contain methods that are shared between all of your application’s controllers. - -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 (refer to "Routes Configuration" for an explanation on how controller actions and parameters are mapped from the URL). - -Code -==== - -Returning to our online bakery example, our RecipesController might contain the view(), share(), and search() actions. The controller would be found in /app/Controller/RecipesController.php:: - - Recipe->findById($id); - $this->set('recipe', $recipe); - } - - } - -Now we can use the helper from our view at /app/View/Recipes/view.ctp:: - -
Example->lowercase('TEXT WILL BE CONVERTED TO LOWERCASE'); ?>
-