Bookcafe

Thursday, March 11, 2010

Customise CakePhp View Part 1 - In My Case



As I said ealier, we can customise our CakePhp according to our own needs.
At the picture above, to remove the section that I have given the number 1 and 2. The following are the steps on how you can do that.

1. To remove 1, you need to create a ctp called default.ctp file and place it in app/views/layouts/

Example of a ctp file can be :

2. To remove 2, you need to change the value of 2 to 0 at line begins with Configure::write('debug', 2); to Configure::write('debug', 0); in app/config/core.php
You can find the meaning of the number in this file.

The end result of the CakePhp view will be as follows:

Monday, March 8, 2010

Simple CakePhp Application - Example

There are about three steps in doing this:

Step 1. Create a datebase and tables and dont forget to insert data into the tables->The name for the tables must be in plural form.

Step 2. Create a php file in app/models directory

- for example syarikat.php->the name of the file must be in singular form

- the code:

class Syarikat extends AppModel
{
var $name = 'Syarikat';
}
?>

Step 3. Create a php file in app/controllers

- for example syarikats_controller.php ->the file name must be filenameplural_controller.php

- the code:

class SyarikatsController extends AppController
{
var $name = 'Syarikats';
var $scaffold;
}
?>

Note: the scaffold variable is use when there is no app/view .thtml file.

The scaffold variable automatically create index.thtml, add.thtml, view.thtml and delete.thtml

If you need to create your own view, process or layout, you can ommit the scaffold variable.

To access your application from browser (in my case)

type at your browser:
http://localhost/cakephp/syarikats

If your get this error (in my case):

Notice (8): Undefined index: id

Then, you must name your first field in the table as ID and make it auto increment.
Example when creating your database
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY

The view of my first application from the browser



Of course you can customised this view according to your needs. For that, I will show to you all in the near future.

First Installation Page of CakePhp 1.6

This is the first page of CakePhp 1.6 after installation.


After the installation, you need to change following:

1. 'Security.salt' in app/config/core.php

2. Rename config/database.php.default to config/database.php

Please read the instructions on the first page to what need to be changed.

It doesn't really matter what the value of the 'Security.salt', as long as it's not easy to guess. You could use an online SHA1 hash generator tool to generate a new long key like what is there by default.

After these steps, you can directly access your database (provided you have set up your database before hand).

If you have successfully edited the files, you should get the following: