Now let's move further. the next part is controller. Controller has logics (some times reffered Business logic in Java). In controller you can write any logical code, such as DB queries, calculations and every thing which you can do in PHP. But remember to use cake functions to 'Make Life Simpler'. The controller should be in app/controllers directory.
You should name controller carefully. The name of controller should be ****_controller.php (replace ****) with your controller name. You should take care about controller name because when you run any page (code) of controller you have to type http://server.com/(Controller)/(Page/Function Name).
Controller class extends AppController. If you want to add some global functions for all controllers, you can write them in cake/app_controller.php. Now lets create our first controller
class UserController extends AppController {
var $name = 'Users'; //Name of controller
#var $layout = 'upload'; //Default Layout for this model
//in case you want to use different layout (I will cover Layouts in next posts)
#var $uses = array('User'); //If you want to use more then one table (Model) then add in uses array.
#var $components = array('Email'); //Components to be used in this controller (I will cover components in next posts)
function index() // Default function, when called show index page. { }
}
AbhinavZone cakephp 1.2 manual and cakephp 1.2 API fun and knowledge
Wednesday, July 18, 2007
How to Install cakePHP (Cake PHP)
I got some comments about installing cakephp. please follow this link to get full guide. If you have any trouble then post here.
http://manual.cakephp.org/chapter/installing
http://manual.cakephp.org/chapter/installing
Friday, June 8, 2007
CakePHP: Model
o hi..I was too busy form past few days.. didn't had tm 2 update it so lets start..
BAsically cake php is a php framework, based on MVC (Model - View - Controller)architecture. Model belongs to data. it directly associated with DB. We can definecertain DB properties, primary keys, table relationships in to model. so overall model can be think as a Database Proxy.hmm I know what question is in your mind.. Why I need Model?? hmm rite?.. ok let me explainBAsically model is abstract view of database. all the complex operation on databbase cas bedone with ease by using model functions. suppose you hav 40 columns in your DB, for inserting data you need to write a long query (near abt 1000 words), but using model just use Model::save() function.. Cool..!! no.....
need more ok..Now another cool feature is data validation. suppose you want that password must be 6-15 digit longand username must not be blank. In traditional design you need to write a long code which may take 15 minuts.But here just define it in model in few seconds and u r done!! .. A lots of more features are there.. I will tell you in next posts.
Now lets create a simple model, User
/** * Constructing model for the application. This model maps 'addresses' * table in database. It receives command from controller and applies * it to database */
class User extends AppModel {
var $name = 'User'; // Name of Model, We will use this name in our controller and view to refer 'tbl_user' table.
var $useTable = 'tbl_user'; // Name of table
var $primaryKey = 'user_id'; // Primary key
// Validation criteria
var $validate = array( 'username' => array('rule' => array('between', 6, 15), 'message' => 'Username must 6 - 15 character long.'), 'password' => array('rule' => array('between', 6, 15), 'message' => 'Password must 6 - 15 character long.'), 'email' => array('rule' => array('email'), 'message' => 'Please enter valid email'), 'first_name' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter first name.'), 'last_name' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter last name.'), 'address_line_1' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter address'), 'city' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter city.'), 'country' => array('rule' => array('between', 1, 1000), 'message' => 'Please select country'), 'day_phone' => array('rule' => array('between', 1, 20), 'message' => 'Please enter valid phone number.'), 'zip' => array('rule' => array('between', 1, 7), 'message' => 'Please enter valid zip code.') );
}
?>
BAsically cake php is a php framework, based on MVC (Model - View - Controller)architecture. Model belongs to data. it directly associated with DB. We can definecertain DB properties, primary keys, table relationships in to model. so overall model can be think as a Database Proxy.hmm I know what question is in your mind.. Why I need Model?? hmm rite?.. ok let me explainBAsically model is abstract view of database. all the complex operation on databbase cas bedone with ease by using model functions. suppose you hav 40 columns in your DB, for inserting data you need to write a long query (near abt 1000 words), but using model just use Model::save() function.. Cool..!! no.....
need more ok..Now another cool feature is data validation. suppose you want that password must be 6-15 digit longand username must not be blank. In traditional design you need to write a long code which may take 15 minuts.But here just define it in model in few seconds and u r done!! .. A lots of more features are there.. I will tell you in next posts.
Now lets create a simple model, User
/** * Constructing model for the application. This model maps 'addresses' * table in database. It receives command from controller and applies * it to database */
class User extends AppModel {
var $name = 'User'; // Name of Model, We will use this name in our controller and view to refer 'tbl_user' table.
var $useTable = 'tbl_user'; // Name of table
var $primaryKey = 'user_id'; // Primary key
// Validation criteria
var $validate = array( 'username' => array('rule' => array('between', 6, 15), 'message' => 'Username must 6 - 15 character long.'), 'password' => array('rule' => array('between', 6, 15), 'message' => 'Password must 6 - 15 character long.'), 'email' => array('rule' => array('email'), 'message' => 'Please enter valid email'), 'first_name' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter first name.'), 'last_name' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter last name.'), 'address_line_1' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter address'), 'city' => array('rule' => array('between', 1, 1000), 'message' => 'Please enter city.'), 'country' => array('rule' => array('between', 1, 1000), 'message' => 'Please select country'), 'day_phone' => array('rule' => array('between', 1, 20), 'message' => 'Please enter valid phone number.'), 'zip' => array('rule' => array('between', 1, 7), 'message' => 'Please enter valid zip code.') );
}
?>
Sunday, May 27, 2007
My first cake bite - 1
Hi
In my organisation I got a project on cakephp. I nevre hrd abt any framework in php. This is my first php project in which I am using framework. I hav good experience in struts so I am expecting that it will not much hard to understand 4 me.
I have decided to write my daily progress here so that it can help those ppl who r new to this framework.
In my organisation I got a project on cakephp. I nevre hrd abt any framework in php. This is my first php project in which I am using framework. I hav good experience in struts so I am expecting that it will not much hard to understand 4 me.
I have decided to write my daily progress here so that it can help those ppl who r new to this framework.
Thursday, May 17, 2007
Why CakePHP?
It has many features that makes it a great framework for developing applications swiftly and with the least amount of hassle. Here are a few in no particular order:
It has many features that makes it a great framework for developing applications swiftly and with the least amount of hassle. Here are a few in no particular order:
- Active, friendly community
- Flexible Licensing
- Compatibility with PHP4 and PHP5
- Integrated CRUD for database interaction and simplified queries
- Application Scaffolding
- Model View Controller (MVC) Architecture
- Request dispatcher with good looking, custom URLs
- Built-in Validation
- Fast and flexible templating (PHP syntax, with helpers)
- View Helpers for AJAX, Javascript, HTML Forms and more Security, Session, and Request Handling Components
- Flexible access control lists
- Data Sanitization
- Flexible View Caching
- Works from any web site subdirectory, with little to no Apache configuration involved
Introduction to CakePHP
What is CakePHP?
CakePHP is a free and open-source rapid development framework for PHP.It composit of a structure of libraries, classes & run-time infrastructure for web application programmers creating web applications originally inspired by the Ruby on Rails framework. Yes!! Its true... Now you can take advantage of Ruby on Rails in PHP too. The coading style in cake PHP is verymuch similer to Ruby on Rails. The Goal of this blog is to enable you to work in a structured and rapid manner - without loss of flexibility.
CakePHP is a free and open-source rapid development framework for PHP.It composit of a structure of libraries, classes & run-time infrastructure for web application programmers creating web applications originally inspired by the Ruby on Rails framework. Yes!! Its true... Now you can take advantage of Ruby on Rails in PHP too. The coading style in cake PHP is verymuch similer to Ruby on Rails. The Goal of this blog is to enable you to work in a structured and rapid manner - without loss of flexibility.
Subscribe to:
Comments (Atom)