Saturday 2 June 2012

Cakephp - a powerful framework of php


Cakephp is a powerful framework of php. it is not a content management framework like wordpress or joomla. but it is a flexible framework which can be used to do anything. it is like the frameworks codeigniter,yii.etc.. 
 A framework means,it has bult in libraraies in itself so that we do not have to code some ceratin functions. like in case of databse insertion,deletion,update,fetching data.etc. it has it's own bult in function. we only have to call these functions. so that we do not have to code by touching in the core.
 This cakephp is an MVC framework.
 M stands for model
 V stands for view
 C stands for controller

 Model is the file which connects the view with the databse. we can only do operations in table with the help of model. 
 View is the html file we are seeing. it has to saved in ctp format.
 Controller links the ctp view with the model

 Theirv are certain format in which the files have to be arranged.it is only according to tghe rules of framework.
 The controller files have to be saved in /app/controller folder. if u have to create an indexcontroller name it as
 IndexController.php  : the first letter should be in caps. and with everycontroller Controller name should be suffixed.
 for eg:
 <?php
class IndexController extends AppController{

public $uses = array('Pages','Flash','SessionManager','User','News','Banner','Mainsettings','Career','Userownerenquiry','PropertyDetails','Uploader','Page','Emirates','Projects','Place','Property','Userproperty','Propertyimage','Main','Sub','Validator','Emailtemp');
public $components = array('Session','Email');

function init(){
$this->Flash->Session=$this->Session;
$this->SessionManager->Session=$this->Session;
}

function index(){
$this->init();
$this->layout ='userIndex'

}

}
?>

when a controller is created this class should be extended with AppController which is built in component...

Model
...........................

model has to be placed in /app/model/folder. it has to be named correctly. if model name is user.
craete User.php and save in that folder. firast letter should be caps.
for eg:
<?php
class User extends  AppModel{
public $name = 'User';
public $useTable = 'user';
public $primaryKey = 'user_id';

}

?>
every model should extend to Appmodel which is built in model of cakephp

View
.....................

view files should be created in /app/view/
and in the folder name of controler. i u have Index controller then create a folder named Index and save the action named ctp files in it... these ctp files are html files. here no databse opertation posssible
for eg:
?php  
$urlRoot=Router::url('/',false);
?>
<div id="content">
<ul id="subMenus">
        <li><a href="<?php echo $urlRoot; ?>admin/settings/index/">Main Types</a></li>
        <li><a href="<?php echo $urlRoot; ?>admin/sale/index/">Sale Method</a></li>
         <li><a href="<?php echo $urlRoot; ?>admin/property/index/">Property Types</a></li>
 <li><a href="<?php echo $urlRoot; ?>admin/emirates/index/">Emirates</a></li>
<li><a href="<?php echo $urlRoot; ?>admin/place/index/">Place in Emarates</a></li>
<li><a href="<?php echo $urlRoot; ?>admin/projects/index/">Projects</a></li>
<li><a href="<?php echo $urlRoot; ?>admin/propertystatus/index/">Property Status</a></li>
<li class="visited"><a href="<?php echo $urlRoot; ?>admin/country/index/">Country</a></li>
<li><a href="<?php echo $urlRoot; ?>admin/settings/generalsettings/">General Settings</a></li>
<li><a href="<?php echo $urlRoot; ?>admin/faq/index/">FAQ</a></li>
    </ul>

<form method="post" action="<?php echo $urlRoot ?>admin/country/index/">
<input type="hidden" name="count" id="count" value="<?php echo $total; ?>" />
<ul id="tabs">
<div id="pageHead"><h1>Country Listing</h1></div>
<ul id="subNav">
<li><input type="submit" name="delete" value="Delete" tabindex="10" class="iconDelete" title="Delete Pages" onclick="return del();" /></li>
<!--<li><input type="submit" name="normalize" value="Normalize" tabindex="11" class="iconNormalize" title="Normalize Content" /></li>
<li><input type="submit" name="featured" value="Featured" tabindex="11" class="iconFeatured" title="Featured Content" /></li>-->
<!--<li><input type="submit" name="default" value="Default" tabindex="11" class="iconDefault" title="Set as Default-Home" /></li>-->
<li><input type="submit" name="updateOrder" value="Set Order" tabindex="12" class="iconOrder" title="Set Order" /></li>
<li><input type="submit" name="unpublish" value="Unpublish" tabindex="13" class="iconUnpublish" title="Unpublish List" /></li>
<li><input type="submit" name="publish" value="Publish" tabindex="14" class="iconPublish" title="Publish List" /></li>
<li><input type="submit" name="add" value="AddNew" tabindex="15" class="iconAdd" title="Add new Page" /></li>
</ul>
<li class="box">
<div class="row">
<span class="message"><?php if(isset($msg)){ echo $msg; } ?></span>
</div>

No comments:

Post a Comment