My First Simple CakePHP Webpage

June 14, 2007 at 6:09 am | In tutorial | 10 Comments

1. Create a table.

- create using http:\\localhost\myphpadmin

- using SQL Codes

CREATE TABLE guestbooks (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(50),
lastname VARCHAR(50),

address VARCHAR(50),
description TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);

Note: The name of the table is in plural form. (example: guestbooks)

2. Creating a .php file in app/models directory

- filename is in singular form (example guestbook.php)

- example code:

<?php
class Guestbook extends AppModel
{
var $name = 'Guestbook';
}
?>

3. Creating a .php file in app/controllers

- the file name must be filenameplural_controller.php (example: guestbooks_controller.php)

- example code:

<?php
class GuestbooksController extends AppController
{
var $name = 'Guestbooks';
var $scaffold;
}
?>

Note: the scaffold variable is use when there is no app/view .thtml file. If you paid attention to the previous example, you will notice that no view files were created. That’s because Cake uses predefined templates for scaffolding; in reality, you’ll need a view for almost every action listed in your controller.

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

That’s all you have your very first simple webpage using cakePHP!!!

Next time we will modify that page of by removing the scaffold variable…

10 Comments »

RSS feed for comments on this post. TrackBack URI

  1. I just started CakePHP about a week ago. My jaw is still on the floor with all it can do.

    I’ve heard of Ruby On Rails but never looked into it because I wasn’t in the mood to learn a new language. CakePHP brings the Rails to PHP.

    Baz L
    Baz Web Development

  2. “That’s all you have your very first simple webpage using cakePHP!!!”

    It would be helpful to mention which file to run from browser, what folders to add to php.ini include, and other stuff like that since many new-to-cake people will be reading this.

  3. Hey Mariecon,

    I agree with Gavin, why not post a tutorial how you did it, not just using scaffolding though. I’ll help if you need one ;)

    Rachel

  4. Hello rachel :)

    Actually i have already make one hehehe…
    Take a look at this http://marieconbgdlr.wordpress.com/2007/06/18/continuation-of-my-first-simple-cakephp-webpage/

    Thanks for dropping by…

  5. Thats great. I think I missed that when I was surfing your blog. Do you mind to document this for our google group? I think I invited you a few days ago.

    Thanks,
    Rachel

  6. Hi rachel :)

    Sure i’m glad to post there :D

  7. Hi marie,

    I am a bit confused as the guestbook example is not working. i just did it was suggested but i am yet to meet with success.

    i have apache server. in httdocs i have placed the downloaded cakephp framework. And as suggested created the table,.php files in app\controllers adn app\models. and tried out using the link:

    http://localhost:8080/cake/guestbooks/

    But i am thrown the following error:

    “requested URL /cake/guestbooks/ was not found on this server”

    Can you please help me.

    Mahesh.

  8. Marie,

    One more thing.. is there any requirement to change paths in any of the files.

    Mahesh

  9. very interesting, but I don’t agree with you
    Idetrorce

  10. I would like to see a continuation of the topic


Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.