NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home / News / Webmaster / Tips and Tricks

Tips and Tricks


Introduction to CakePHP Plugins

How to create your first CakePHP plugin

By Adrian Placinta, Web News Editor

14th of September 2007, 15:13 GMT

Adjust text size:



Enlarge picture
Do you want to create a blog, a web management module, or anything you want for an application? Make it a CakePHP plugin and you can also put it in other applications. The main tie between a plugin and the application it has been installed into is the application's configuration (database connection etc.). Otherwise, it operates in its own little space, behaving much like it would if it were an application on its own.

To start, place your plugin files
in /app/plugins folder. Choose wisely the name of the folder for the plugin files because it will be used in many places. For any normal application, you do not need to define AppController and AppModel; that's required for the plugins. You'll need to create them before your plugin works. These two special classes are named after the plugin, and extend the parent application's AppController and AppModel. For example, the AppController will be /app/plugins/softpedia_test_controller.php and the AppModel /app/plugins/softpedia_test_model.php. If you forgot to define these classes, CakePHP will show you "Missing Controllers" error until you solve the problem.

The controllers for the plugin will be stored in /app/plugins/name_of_plugin/controller. In order to avoid namespace conflict, you should give the controller a unique name. The models of the plugin are stored in /app/plugins/name_of_plugin/models. Next, you will specify the place where you will put the plugin views. Views for the plugin have the same functions as in normal applications. Place the views in /app/plugins/name_of_plugin/views folder.

Before starting to create your CakePHP application, you should consider the following conventions:
- model filenames are singular, capitalized for single-word models, and UpperCamelCased for multi-word models.Also model filenames use a lower-case underscored syntax: e.g: softpedia_test.php
- table names are plural and lowercased
- foreign keys should always be: table_name_in_singular_form_id: user_id (foreign key) users (table)
- controller filenames are plural and underscored with "controller" appended: controller_name_controller.php

You can find all the conventions in the manual.

TAGS:

CakePHP | plugins | PHP framework
Read by 6,509 user(s) | Add comment | Link to this article TWEET THIS


Article rating:
Good (3.3/5) 10 vote(s)    

Subscribe to news | Print article | Send to friend

© Copyright 2001-2009 Softpedia
Contact:

 

 

SEARCH THE NEWS ARCHIVE :




Today's News
| Yesterday's News | News Archive


MORE RELATED ARTICLES:


CakePHP - PHP development framework

Installation and Database Configuration of CakePHP

Configuration of core.php for CakePHP

User opinions:

No user comments yet.
Be the first to express your opinion using the form below!

Share your opinion:

Your Name:
Your Email Address:
(will not be used for commercial purposes)
Solve this to prove you're not a bot: =
Your review/opinion:

 




Windows tabGames tabDrivers tabMac tabLinux tabScripts tabMobile tabHandheld tabGadgets tabNews tab

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   ENTER NEWS SITE   |   ENGLISH BOARD   |   ROMANIAN FORUM