From bac6eb1c262a88632a2d6ddb4f1daa169477f242 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Thu, 15 May 2014 18:28:47 +0700 Subject: [PATCH] Our own docs is lacking, and cakephp docs is way better --- en/developers/understanding-cakephp.rst | 11 +--- .../understanding-cakephp/behaviors.rst | 65 ------------------- .../understanding-cakephp/components.rst | 47 -------------- .../understanding-cakephp/controllers.rst | 50 -------------- .../understanding-cakephp/helpers.rst | 61 ----------------- .../understanding-cakephp/models.rst | 46 ------------- en/developers/understanding-cakephp/views.rst | 25 ------- 7 files changed, 1 insertion(+), 304 deletions(-) delete mode 100644 en/developers/understanding-cakephp/behaviors.rst delete mode 100644 en/developers/understanding-cakephp/components.rst delete mode 100644 en/developers/understanding-cakephp/controllers.rst delete mode 100644 en/developers/understanding-cakephp/helpers.rst delete mode 100644 en/developers/understanding-cakephp/models.rst delete mode 100644 en/developers/understanding-cakephp/views.rst 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'); ?>

-
\ No newline at end of file diff --git a/en/developers/understanding-cakephp/models.rst b/en/developers/understanding-cakephp/models.rst deleted file mode 100644 index 0b5c870..0000000 --- a/en/developers/understanding-cakephp/models.rst +++ /dev/null @@ -1,46 +0,0 @@ -Models -###### - -Read the CakePHP docs on Models: http://book.cakephp.org/2.0/en/models.html. - -What is a Model? -================ - -Models represent data and are used in CakePHP applications for data access. A model usually represents a database table but can be used to access anything that stores data such as files, LDAP records, iCal events, or rows in a CSV file. - -A model can be associated with other models. For example, a Recipe may be associated with the Author of the recipe as well as the Ingredient in the recipe. -Code - -If you have a table named 'recipes' (with columns id, title, body), the model name would be Recipe and found at `/app/Model/Recipe.php`:: - - Recipe->findById(123); - - // set the $recipe variable so it can be used by views later - $this->set('recipe', $recipe); // or $this->set(compact('recipe')); - } - - } \ No newline at end of file diff --git a/en/developers/understanding-cakephp/views.rst b/en/developers/understanding-cakephp/views.rst deleted file mode 100644 index 482bd7e..0000000 --- a/en/developers/understanding-cakephp/views.rst +++ /dev/null @@ -1,25 +0,0 @@ -Views -##### - -Read the CakePHP docs on Views: http://book.cakephp.org/2.0/en/views.html. - -What is a View? -=============== - -Views are the V in MVC. Views are responsible for generating the specific output required for the request. Often this is in the form of HTML, XML, or JSON, but streaming files and creating PDF's that users can download are also responsibilities of the View Layer. - -Code -#### - -From previous example of Recipes, we will be placing out view file at `/app/View/Recipes/view.ctp`:: - -
-

- -

-
- -Plugin Views ------------- - -If it is Recipes plugin's view, it would be found at `/app/Plugin/Recipes/View/view.ctp`. \ No newline at end of file