Cake: let PHP also run on rails

Source: Internet
Author: User
Tags php foreach
Cake is a php framework based on RubyonRails. Like RoR, Cake also encapsulates database control. Currently, Cake is not a mature framework, but it is worth noting. How to install Cake on WAMP

Cake is a php framework based on Ruby on Rails. Like RoR, Cake also encapsulates database control. Currently, Cake is not a mature framework, but it is worth noting.

The following describes how to install Cake on WAMP.

First Download Cake Latest version: cake_0.2.9.zip


After decompression, enter cakeconfig to change database. php. default to database. php, and set database parameters. For example:

$ DATABASE_CONFIG = array (
'Devel '=> array (
'Host' => 'localhost ',
'Login' => 'user ',
'Password' => 'user ',
'Database' => 'Cake'
)
);

Then Cake needs to use Apache mod_rewrite, open Apache/config/httpd. conf, and

# LoadModule rewrite_module modules/mod_rewrite.so

Before,

Set

# AddModule mod_rewrite.c

The first # is dropped.

Then add a VM, such


ServerAdmin Easy@gmail.com
DocumentRoot 'f:/cake /'
ServerName cake.com
ErrorLog logs/cake.com. error_log
CustomLog logs/cake.my.com common


AllowOverride all
Order allow, deny
Allow from all

In C: WINDOWSsystem32driversetchosts, add a local host line.

127.0.0.1 cake.com

Restart Apache and the browser.

Now Cake can work properly. Let's create a Exploitation:

Create a table in the database

CREATE TABLE posts (    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,    title VARCHAR(50),    body TEXT,    created DATETIME DEFAULT NULL,    modified DATETIME DEFAULT NULL);INSERT INTO posts (title,body,created)     VALUES ('The title', 'This is the post body.', NOW());INSERT INTO posts (title,body,created)     VALUES ('A title once again', 'And the post body follows.', NOW());INSERT INTO posts (title,body,created)     VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
Cake is based on the MVC mode. When creating an application, we first create its Model.
app/models/post.php
  
Create Control
app/controllers/posts_controller.php
    
Here, the index method is used:
app/controllers/posts_controller.php (fragment) function index () {}
Create view
app/views/posts/index.thtml
      
       post->find_all() as $post): ?> 
        
ID Title Created

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.