CakePHP 2 simple test example

Source: Internet
Author: User

1. First create your own table

Set foreign_key_checks = 0;
------------------------------
-- Table structure for posts
------------------------------
Create Table 'posts '(
'Id' int (10) unsigned not null auto_increment,
'Title' varchar (50) default null,
'Body' text,
'Created 'datetime default null,
'Modified' datetime default null,
Primary Key ('id ')
) Engine = InnoDB default charset = GBK;

------------------------------
-- Records
------------------------------
Insert into 'posts' values ('1', 'the title', 'This is the post body. ', '2017-06-16 10:04:05', null );
Insert into 'posts' values ('2', 'a title once again ',' and the post body follows. ', '2017-06-16 10:04:05', null );
Insert into 'posts' values ('3', 'title strikes back', 'This is really exciting! Not. ', '2017-06-16 10:04:05', null );
Insert into 'posts' values ('4', '000000', '33', '2017-06-16 06:03:06 ', '2017-06-16 06:03:06 ');

2. Add the post. php file in models.

<? PHP
Class Post extends appmodel {
VaR $ name = 'post ';
}
?>

3. Add posts_controller.php under the controllers directory

<? PHP
Class postscontroller extends appcontroller {
VaR $ name = 'posts ';
VaR $ scaffold;

}
?>

4. Enter http: // 127.0.0.1: 8081/posts in IE

You can see the following results

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.