Skip to main content

CakePHP Programmer's Reference Guide

What is CakePHP?

CakePHP is a free open-source rapid development framework for PHP. Its a structure of libraries, classes and run-time infrastructure for programmers creating web applications originally inspired by the Ruby on Rails framework. Our primary goal is to enable you to work in a structured and rapid manner - without loss of flexibility.

History of CakePHP

In 2005, Michal Tatarynowicz wrote a minimal version of a Rapid Application Framework in PHP. He found that it was the start of a very good framework. Michal published the framework under the MIT license, dubbing it Cake, and opened it up to a community of developers, who now maintain Cake under the name CakePHP.

Introduction

This chapter is a short, casual introduction to MVC concepts as they are implemented in Cake. If you're new to MVC (Model View Controller) patterns, this chapter is definitely for you. We begin with a discussion of general MVC concepts, work our way into the specific application of MVC in CakePHP, and show some simple examples of CakePHP using the MVC pattern.

The MVC Pattern

Model-View-Controller is a software design pattern that helps you logically separate your code, make it more reusable, maintainable, and generally better. Model View Controller was first described by the author group Gang of Four. Dean Helman wrote (an extract from Objective Toolkit Pro white paper):

"The MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: the model, the view, and the controller. MVC was originally developed to map the traditional input, processing, output roles into the GUI realm.

Input -> Processing -> Output

Controller -> Model -> View

"The user input, the modeling of the external world, and the visual feedback to the user are separated and handled by model, view port and controller objects. The controller interprets mouse and keyboard inputs from the user and maps these user actions into commands that are sent to the model and/or view port to effect the appropriate change. The model manages one or more data elements, responds to queries about its state, and responds to instructions to change state. The view port manages a rectangular area of the display and is responsible for presenting data to the user through a combination of graphics and text."

In Cake terms, the Model represents a particular database table/record, and it's relationships to other tables and records. Models also contain data validation rules, which are applied when model data is inserted or updated. The View represents Cake's view files, which are regular HTML files embedded with PHP code. Cake's Controller handles requests from the server. It takes user input (URL and POST data), applies business logic, uses Models to read and write data to and from databases and other sources, and lastly, sends output data to the appropriate view file.

To make it as easy as possible to organize your application, Cake uses this pattern not only to manage how objects interact within your application, but also how files are stored, which is detailed next.

Overview of the Cake File Layout

When you unpack Cake on your server you will find three main folders -

      app       cake       vendors       

The cake folder is where the core libraries for Cake lay and you generally won't ever need to touch it.

The app folder is where your application specific folders and files will go. The separation between the cake folder and the app folder make it possible for you to have many app folders sharing a single set of Cake libraries. This also makes it easy to update CakePHP: you just download the latest version of Cake and overwrite your current core libraries. No need to worry about overwriting something you wrote for your app.

You can use the vendors directory to keep third-party libraries in. You will learn more about vendors later, but the basic idea is that you can access classes you've placed in the vendors directory using Cake's vendor() function.

Let's look at the entire file layout:

/app    
/config          - Contains config files for your database, ACL, etc.       
/controllers     - Controllers go here          
/components  - Components go here      
/index.php       - Allows you to deploy cake with 
/app as the DocumentRoot     
/models          - Models go here       
/plugins         - Plugins go here      
/tmp             - Used for caches and logs      
/vendors         - Contains third-party libaries for this application      
/views           - Views go here         
/elements    - Elements, little bits of views, go here        
/errors      - Your custom error pages go here         
/helpers     - Helpers go here         
/layouts     - Application layout files go here         
/pages       - Static views go here      
/webroot     - The DocumentRoot for the application         
/css         
/files         
/img         
/js  
/cake        - Cake's core libraries. Don't edit any files here.  index.php            
/vendors     - Used for server-wide third-party libraries.  VERSION.txt         
             - Let's you know what version of Cake you're using.
Requirements
In order use CakePHP you must first have a server that has all the required
libraries
and programs to run CakePHP:
Server Requirements
Here are the requirements for setting up a server to run CakePHP:
  1. An HTTP server (like Apache) with the following enabled: sessions,
    mod_rewrite (not absolutely necessary but preferred)
  2. PHP 4.3.2 or greater. Yes, CakePHP works great in either PHP 4 or 5.
  3. A database engine (right now, there is support for MySQL, PostgreSQL and
    a wrapper for ADODB).

    Installing CakePHP

    Getting the most recent stable version

    There are a few ways you can secure a copy of CakePHP: getting a stable

    release from CakeForge, grabbing a nightly build, or getting a fresh version of

    code from SVN.

    To download a stable version of code, check out the files section of the

    CakePHP project at CakeForge by going to http://cakeforge.org/projects/cakephp/.

    To grab a nightly, download one from http://cakephp.org/downloads/index/nightly.
    These nightly releases are stable, and often include the bug fixes between
    stable releases. To grab a fresh copy from our SVN repository, use your
    favorite SVN client and connect to https://svn.cakephp.org/repo/trunk/cake/
    and choose the version you're after.
    Unpacking
    Now that you've downloaded the most recent release, place that compressed

    package on your web server in the webroot. Now you need to unpack the CakePHP

    package.

    There are two ways to do this, using a development setup, which allows you

    to easily view many CakePHP applications under a single domain, or using the

    production setup, which allows for a single CakePHP application on the domain.


    for extends click here

Comments

Popular posts from this blog

A history of Ir. Soekarno

Sukarno This is an Indonesian name; it does not have a family name  Ir. Sukarno 1st President of Indonesia In office 18 August 1945 – 12 March 1967 Prime Minister Sutan Sjahrir Amir Sjarifuddin Muhammad Hatta Abdul Halim Muhammad Natsir Soekiman Wirjosandjojo Wilopo Ali Sastroamidjojo Burhanuddin Harahap Djuanda Kartawidjaja Vice President Mohammad Hatta Succeeded by Suharto Born 6 June 1901 Blitar, Dutch East Indies Died 21 June 1970 (aged 69) Jakarta, Indonesia Political party None Spouse Oetari Inggit Garnasih Fatmawati Hartini Kartini Manoppo Ratna Sari Dewi Soekarno Haryati Yurike Sanger Heldy Djafar Religion Islam Signature  Sukarno, born Kusno Sosrodihardjo (6 June 1901 - 21 June 1970) was the first President of Indonesia. He helped the country win its independence from the Netherlands and was President from 1945 to 1967, presiding with mixed success over the country's turbulent transition to independence. Sukarno was forced out of power by one of his generals, Suharto, who

pemrograman C++

okelah.. sekarang ane iseng mw biki tutor sederhana.. soalnya ini ditanyain pas ane sidang kompre..wkwkwk asik juga sih..dah lama di lupain C++nya.. untung masih rada inget ama perintah perintahnya...so jangan loading terlalu lama.langsung aja ane kasih script sederhana C++ cuman buat nampilin file txt #include <iostream.h>   #include <fstream.h>   #include <conio.h> void main()   {   ofstream textbaru;   textbaru.open("D:/example.txt");   textbaru<<"Ini adalah contoh program menuliskan teks ke dalam file"<<endl;   textbaru.close();   getch();   } nah kan sederhana... ga ribet..bisa di baca dan di jelaskan oleh dirimu sendiri? klo masih ga ngerti sih gampang penjelesannya. script include klo kate dosen ane adalah kunci untuk menyalakan beberapa perintah script yang di gunakan... klo contoh paling gampang ya itu iostream (input output stream) fungsinya buat ngejalanin script cin or cout ofstream di bawah header berfungsi buat man

Instal linux di usb

HAi linux-er mania.... okay langsung ajah tips dari saya tentang membuat live Usb dengan mudah dan cepat, yaitu : 1. Download UNetBootin (pilih sesuai Sistem operasi yang anda gunakan, windows ato linux) disini 2. Siapkan Distro linux yang anda ingin gunakan.... bisa dari cd/dvd, file iso-nya, ato anda punya koneksi internet? bisa otomatis di download sama UNetBootin. 3. Berikut ini daftar Distro Linux yang ringan, yang dapat anda pertimbangkan untuk di instal ke flash disk anda... - DSL (Damn Small Linux - ARCH Linux - xpud-0.9 - clonezilla-live-1.2.2-14 - austrumi-1.7.2 - slax-6.0.7 - Dream Linux - FreeBSD - Elive - System rescue dan lain - lain sebagainya..... 4. Setelah memilih Distro yang cocok, kemudian Pilih flashdisk yang ingin digunakan, minimal kapasitas yang dapat saya anjurkan adalah flashdisk dengan kapasitas minimal 1 GB..... Lalu masukkan FlashDisk ke komputer anda. 5. Jika sistem operasi yang anda gunakan adalah windows, maka tinggal anda klik