Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating custom component in cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 119
    Comment on it

    Cakephp provides number of core components such as Session,cookie ,email etc. Component extends the object class. It allow us to reuse the code and makes our controller code clean. Use camelcase naming convention while creating component.All components suffixed with 'component' .

    class mycustomComponent extends Object {
    
         function myfunc() {
    
         }
    }
    

    The component file is stored under app/controllers/components. Next step is to include component inside controllers So that cakephp know that it exists.

    class mycustomController extends AppController {
            var $components = array('Mycustom');
    }
    

    Next step is to call a component method within a controller.

    class mycustomController extends AppController {
            var $components = array('Mycustom');
            function search() {
            return $this->Mycustom->myfunc();
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: