Pages

Showing posts with label model. Show all posts
Showing posts with label model. Show all posts

Friday, January 25, 2013

What is Cakephp

What is Cakephp?
Cakephp is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. 
It uses commonly known design patterns like MVC,ORM within the convention over configuration paradigm.
It also reduces development costs and helps developers write less code.

MVC=>MODEL VIEW CONTROLLER
ORM =>OBJECT RELATION MAPPING

ORM stands for a technique in which we turn every RELATION(Table) into an OBJECT and its ATTRIBUTES as data members of the class.

*If you are familiar with Entity framework in .Net consider the Db Context class which represents a database
*In regular MVC Model classes are created to represent Tables of the concerned database.

Friday, December 7, 2012

Interview Question on relations in cakephp

Recently I was asked on different types of relations in between models in a cakephp framework

Relationship Association Type Example
one to one hasOne A user has one profile.
one to many hasMany A user can have multiple recipes.
many to one belongsTo Many recipes belong to a user.
many to many hasAndBelongsToMany Recipes have, and belong to many ingredients.

Then I was given 4 tables as follows

Employee:
Eid,fname,lname

Department:
Deptid,deptname

Salary: 
Sid,salary

EmpSalDeptrelation:
eid,sid,deptid

To these I was told to determine how relations will be represented in EmpSalDeptrelation table so that if I fetch 1 employee I get his salary department along

Answer is to the EmpSalDeptrelation model add the relationships as

eid belongsTo Eid of employee,sid belongs to Sid of salary,deptid belongs to Deptid of Department

and then in the respective controller which uses($uses) this model
add
$this->empsaldeptrelation->find();
set the conditions where eid equaks to concerned employee id;