Table of Contents

Table of Contents

Extending Cake

There are several options when it comes to adding functionality to Cake. You may want to add Markdown, maybe you want a method that combines several of Cake’s core functions, lets say you want to add blocks to your views, or get crazy and grab some stuff from another controller.

Vendors

There is a vendors directory in the directory root. Inside this directory you put the library you want to include.

Then, in the top of your controller file, add vendors(’library_name’) and you are free to create any instances of your library classes or use functions defined there. For some more info on vendors go to the vendors documentation.

Components

Components are the preferred way to provide additional functionality to your controller. To make a component available you would add var $component = array(’myComponent’) inside of your controller’s definition, add your file to the /app/controllers/components, name your class MyComponent, and create your methods.

The methods would then be available with $this->mycomponent->method() and variables with $this->mycomponent->var. To learn more go to the components documentation.

Helpers

Helpers are all about the view. You know about the helpers in Cake, but you need a little bit more. You want to have your own methods to display formatted info. To achieve this, you need to add var $helpers = array(’myHelper’).

Now, throw your myhelper.php file into the /app/views/helpers/, create the class MyHelper, and $myHelper is available in the view.

Don’t forget that you can add var $helpers in MyHelper and make use of other helpers there. You can read more about the helpers in Cake in the helpers documentation.

You want more?

Well, the coolest thing in Cake might be the requestAction() method. Check out the documentation. requestAction() allows you to call a method from another controller. You could use it to get a menu or grab info from another model.

 
tutorials/extending_cake.txt · Last modified: 2006/01/10 15:26 by gwoo