This is the script for creating a library application using the cake bake command that I demonstrated at Boise Codecamp 2011 on February 26th, 2011. I will be posting the movie database code later that you can install to a clean host cakephp directory along with resources used in the A Taste of CakePHP presentation along with the slides and resources.
I had installed the cakephp core installed using Ubuntu 10.10 (CakePHP 1.3.2). I also showed how to use the Synaptic Package manager to install cakephp and cakephp-scripts.
Note: You need to be sure that version of CakePHP installed is 1.3.2 or later. I attempted this on Ubuntu 10.04 and it was a much older version, cakePHP version 1.2.5, and it didn't execute correctly. Also, make sure that that your cake install includes cakephp-scripts in using Ubuntu. You can test your install by using the cake bake command. For additional information check CakePHP Console and Code-Generation-with-Bake
First configure database using phpMyAdmin or other tool that easily allows you to insert the following SQL commands:
CREATE DATABASE library;
CREATE USER 'cakephp'@'localhost' IDENTIFIED BY 'cakephp3';
GRANT ALL ON library.* TO 'cakephp'@'localhost' IDENTIFIED by 'cakephp3';
FLUSH PRIVILEGES;
USE library;
CREATE TABLE books (id CHAR(36) NOT NULL PRIMARY KEY,user_id CHAR(36) NOT NULL,title VARCHAR(45) NOT NULL,slug VARCHAR(45) NOT NULL,author VARCHAR(45) NOT NULL,summary TEXT,purchase DATE,created DATETIME,modified DATETIME );
CREATE TABLE users (id CHAR(36) NOT NULL PRIMARY KEY,name VARCHAR(45) NOT NULL,created DATETIME,modified DATETIME );
In terminal session as root:
cd /var/www
enter cake bake project library
Do not select verbose (respond n) when prompted:
Do you want verbose output? (y/n)
[n] > n
Expected Result:
root@clinton-desktop:/var/www/cake bake project library
root@tinslecl-VirtualBox:/var/www# cake bake project library
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
Welcome to CakePHP v1.3.2 Console
---------------------------------------------------------------
App : www
Path: /var/www
---------------------------------------------------------------
Bake Project
Skel Directory: /usr/share/php/cake/console/templates/skel
Will be copied to: /var/www/library
---------------------------------------------------------------
Look okay? (y/n/q)
[y] > y
Do you want verbose output? (y/n)
[n] > n
---------------------------------------------------------------
Created: library in /var/www/library
---------------------------------------------------------------
Creating file /var/www/library/views/pages/home.ctp
Wrote `/var/www/library/views/pages/home.ctp`
Welcome page created
Random hash key created for 'Security.salt'
Random seed created for 'Security.cipherSeed'
CAKE_CORE_INCLUDE_PATH set to /usr/share/php in webroot/index.php
CAKE_CORE_INCLUDE_PATH set to /usr/share/php in webroot/test.php
Remember to check these value after moving to production server
You can now test your "sweet build" of library by opening:
http://localhost/library
Next steps, in a terminal session as root:
1. cd /var/www/library/config/
2. cp database.php.default database.php
Configure library/apps/config/database.php for database settings as shown:
3. vi database.php
* For MySQL, MySQLi, Postgres and DB2, specifies the character encoding to use when connecting to the
* database. Uses database default.
*
*/
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakephp',
'password' => 'cakephp3',
'database' => 'library',
'prefix' => '',
);
4. cd ..
(You should be at the root of library as in /var/www/library)
(Execute the follow commands at the /library# prompt as shown)
5. root@clinton-desktop:/var/www/library# cake bake model all
6. root@clinton-desktop:/var/www/library# cake bake controller all
7. root@clinton-desktop:/var/www/library# cake bake view all
You should now be able to go http://localhost/library/books and see your completed application! The first task is to click on New User and add your first user.
Cheers. It Just Works!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment