[CakePHP] controller convention

Controller convention in CakePHP
[ qui ước đặt tên controller trong cakephp ]

////////////////////////////////////////////////////////////
Conventions
////////////////////////////////////////////////////////////
Controller classnames are plural, CamelCased, and end in Controller
classnames are CamelCased


note:
+ the first method that you write for a controller might be the index() method.
- when a request specifies a controller but not an action, the default CakePHP
behavior is to execute index() method of that controller.
+ Example:
- http://www.dekvn.rps/razor maps to call index() method of the RazorController,
whereas http://www.dekvn.rps/razor/view/ maps to call on the view() method of RazorController

Change the visibility of controller by prefixing the name with underscoress

////////////////////////////////////////////////////////////
Examples
////////////////////////////////////////////////////////////
Controler classnames:
PeopleController
LatestArticlesController

Change controller visibility
classnames NewsController extends AppController{
function latest() {
$this->_findNewArticles();
}

function _findNewArticles() {
//logic to find the latest news article
}
}
?>

--> while the page: http://wwww.example.com/news/latest would be accessible
to user as usual, but http://www.example.com/news/_findNewArticles would get an error

---
name: hoang nguyen
nickname: mathhoang
Y!M: vietnam_hoangminhnguyen@yahoo.com
mail: vietnam_hoangminhnguyen@Yahoo.com
site: http://tech-vnit.tk
---

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...