CakePHP, installazione

Visto che conosco e lavoro soprattutto con PHP ma mi affascina molto Ruby on Rails ho deciso di provare CakePHP, framework web PHP da molti paragonato al celebre framework scritto in Ruby.

cakePHP

Installazione di cakePHP:

Manuale cakePHP

Requisiti:

  • An HTTP server (like Apache) with the following enabled: sessions, mod_rewrite (not absolutely necessary but preferred)
  • PHP 4.3.2 or greater. Yes, CakePHP works great in either PHP 4 or 5.
  • A database engine (right now, there is support for MySQL 4+, PostgreSQL and a wrapper for ADODB).

Userò Apache, PHP 5 e MySQL.

Scaricare la versione stabile e scompattarla

cake_1.1.19.6305.tar.gz

Esistono due tipi di configurazione per lo sviluppo e per la produzione.

Produzione
In ambiente di produzione è meglio installare CakePHP in una directory indipendente configurando poi il Web server in modo che la cartella di root corrisponda a /path/di/cakephp/app/webroot.

Sviluppo
In ambiente di sviluppo è sufficiente scompattare i sorgenti nella directory di root, all’interno della directory cake.

Io utilizzerò la configurazione per lo sviluppo.

Schema applicazione
/app
   /config
   /controllers
      /components
   /models
   /plugins
   /tmp
   /vendors
   /views
      /elements
      /errors
      /helpers
      /layouts
      /pages
   /webroot
      /css
      /files
      /img
      /js
   /index.php
/cake
/docs
/vendors
/index.php

Configurazione Apache
attivo il modulo mod_rewrite ed ed utilizzo il file .htaccess fornito all’interno dell’installazione standard per poter utilizzare URL puliti e chiari da leggere che non facciano uso di query string.
riscrivere gli url con il modulo modrewrite di apache

Configurazione database
E’ necessario configurare l’accesso al database. Per fare questo bisogna modificare il file app/config/database.php.default e rinominarlo in database.php, modificando i valori dell’array $default.
<br /> var $default = array('driver' => 'mysql',<br /> 'connect' => 'mysql_connect',<br /> 'host' => 'localhost',<br /> 'login' => 'user',<br /> 'password' => 'password',<br /> 'database' => 'project_name',<br /> 'prefix' => '');<br />

Creo il database cake

Se vado a http://localhost/cake vedo:

CakePHP Rapid Development

Your database configuration file is present.

Cake is able to connect to the database.

CakePHP release information is on CakeForge
Read the release notes and get the latest version
Editing this Page

To change the content of this page, create: /app/views/pages/home.thtml.
To change its layout, create: /app/views/layouts/default.thtml.
See the views section of the manual for more info
You can also add some CSS styles for your pages at: app/webroot/css/.

Ora sono pronto per scrivere la mia prima applicazione con CakePHP.

Gabba gabba hey
Bonzo