lazy saunter

(personal learnings in computation)

Monday, August 25, 2008

cakePHP, 2

post-project:

cakephp would allow fairly rapid development of LAMP (and CRUD) apps
once the initial learning curve is surpassed. in a self-conceived
project, i went one step beyond the simple tutorial and treated a
table with a primary key and a table with a foreign key referencing
the first table's primary key.

in my case, i wanted to maintain notes that i had recorded dealing with
articles that i had read. each article can have multiple notes associated
with it.

cakephp wants the primary key in the "articles" table to be named "id" and the foreign key in the "notes" table referencing the PK from "articles" to be named "article_id". there are ways to get around this if the table structure is already set. files must be named in a similarly strict manner as well as the class names in those files.

although this is listed in the installation/configuration part of the cakephp website, these are the steps i took to create/complete installation and a first project:

1- install the cakephp files in a web-accessible directory, rename the dir ("notes")
2- make the app/tmp dir writable by apache (777)
3- create the DB
4- configure the DB config file
5- create model for "articles" table: article.php
6- create controller for "articles"
7- create articles dir under views
8- create file under views/articles/ called index
9- make an action (in controller) for add
10- create add view
11- make an action for delete
12- make an action for edit
13- create edit view

along the way i discovered a few other tricks for customizing the application:
- an easy function for logging which goes in the controller
- how to change the layout (views)
- how to use scaffolding

with scaffolding, only steps 1-6 are required for setting up a CRUD
application. a "scaffold" variable must be declared (in the controller).

the installation of cakephp 1.1 is ~1.6M which is a lot compared to a
project consisting of 20 or 30 PHP text files. i don't know how this
affects performance but it is something to remember. version 1.2 is ~6.9M.

while still in beta (i assume), i would use v 1.2 in the future if i am
to actually use cakephp in a project.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home