To use WordPress for developing a web application

前端 未结 10 2036
旧时难觅i
旧时难觅i 2020-12-15 14:49

I\'m planning to develop a web application which will have many static pages (about, help, contact, etc.) and other dynamic pages for the application.

Most of the ti

10条回答
  •  隐瞒了意图╮
    2020-12-15 15:55

    Use WordPress on the admin side for editing the textual content (and even menus). But use a custom CakePHP app to output that content.

    CakePHP can read formatted content straight off the WordPress database tables (or a custom views). You need to define a new database connection and a new model (e.g. Post).

    Here's a sample example implementation:

    A new database connection in /app/database.php:

    class DATABASE_CONFIG {
        // ...
        var $wp = array(
                'driver' => 'mysql',
                'persistent' => false,
                'host' => 'localhost',
                'login' => '',
                'password' => '',
                'database' => '',
                'prefix' => 'wp_',
        );
    }
    

    A new model in /app/models/post.php:

    class Post extends AppModel {
        var $primaryKey = 'ID';
        // Could define relations
    }
    

    Any controller now can fetch the content, e.g.:

    class XxxController extends AppController {
    
        function index($postName) {
            $this->set('post', $this->Post->findByPostName($postName));
        }
    
    }
    

    And the view can simply output the HTML content of the post:

    
    

    Here is a more elaborate example: http://code.google.com/p/cakephp-wordpress/.

提交回复
热议问题