Welcome to the Cookbook

loading...

5 Core Components

ada perubahan yang masih ditangguhkan untuk bagian ini. More information about translations

CakePHP has a number of built-in components. They provide out of the box functionality for several commonly used tasks.

AclThe Acl component provides an easy to use interface for database and ini based access control lists.
AuthThe auth component provides an easy to use authentication system using a variety of authentication processes, such as controller callbacks, Acl, or Object callbacks.
CookieThe cookie component behaves in a similar fashion to the SessionComponent in that it provides a wrapper for PHP's native cookie support.
EmailAn interface that can be used to send emails using one of several mail transfer agents including php's mail() and smtp.
RequestHandlerThe request handler allows you to introspect further into the requests of your visitors and inform your application about the content types and requested information.
SecurityThe security component allows you to set tighter security and use and manage HTTP authentication.
SessionThe session component provides a storage independent wrapper to PHP's sessions.

To learn more about each component see the menu on the left, or learn more about creating your own components.

All core components now can be configured in the $components array of a controller.

<?php
class AppController extends Controller {

    var $components = array(
        'Auth' => array(
            'loginAction' => array('controller' => 'users', 'action' => 'signOn'),
            'fields' => array('username' => 'email', 'password' => 'password'),
        ),
        'Security',
        'Email' => array(
            'from' => 'webmaster@domain.com',
            'sendAs' => 'html',
        ),
    );
}
  1. <?php
  2. class AppController extends Controller {
  3. var $components = array(
  4. 'Auth' => array(
  5. 'loginAction' => array('controller' => 'users', 'action' => 'signOn'),
  6. 'fields' => array('username' => 'email', 'password' => 'password'),
  7. ),
  8. 'Security',
  9. 'Email' => array(
  10. 'from' => 'webmaster@domain.com',
  11. 'sendAs' => 'html',
  12. ),
  13. );
  14. }

You can override the settings in the controller's beforeFilter()

<?php
class MembersController extends AppController {

    function beforeFilter() {
        $this->Email->from = 'support@domain.com';
    }
}
  1. <?php
  2. class MembersController extends AppController {
  3. function beforeFilter() {
  4. $this->Email->from = 'support@domain.com';
  5. }
  6. }