开发者

To use WordPress for developing a web application

开发者 https://www.devze.com 2023-02-02 15:28 出处:网络
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.

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 time I use CakePHP to develop any of my applications, but for this project I have being thinking about using WordPress as a framework for my applications. The reason is because in WordPress it will be easy to create the static pages (easy to write the static pages contents) an开发者_如何学编程d because the user registration in WordPress already exists (I don't have to build it).

But on other hand, CakePHP is easy for me, and I will be focusing in building my application, not learning a new framework.

Let me know what you think. Should I use WordPress as the core of my application or use CakePHP?

PS: my application will be mainly a search engine using Sphinx to look up large data in a database and display the result for the users and some other easy PHP (dynamic) pages.


I read many of the analysis on towards deciding for a base framework for my next project. Here are the conclusions;

(PS: I am heavily coding in WordPress for the past one year, and I am an experienced web developer and software architect for more than 18 years)

Argument 1 - 'WordPress is a CMS / blog engine, but not an application framework'

It is like saying 'Microsoft is a technology company'.

Which is simply not TRUE. (Yes, Microsoft creates good technology, but it is a marketing company. E.g.: Its competitive edge is not creating the best technology on earth, but pushing what it does successfully on to business decision makers.)

WordPress is a solid application platform and CMS/blog functionality is the default application that comes in the box. I think the main reason why WordPress is under estimated as a development platform 1) custom post types / custom fields functionality is so new; we haven't seen enough applications benefit these features. 2) A very high percentage of the WordPress community is non-technical people (designers, bloggers etc.) compared to other 'low-level platforms' such as CakePHP, CodeIgniter, etc. So the non-WordPress developer community is not aware of what WordPress can really do.

Argument 2 - WordPress is not based on MVC so it is not a credible development platform.

Sorry, but it is not TRUE.

MVC is not new-age religion that everybody should follow. Yes, it simplifies debugging, development with it structural approach to coding. At the end of the day it is an approach (among many others) to make your life easier as a programmer and save you company's valuable investment embedded into your code.

Plugin architecture and theme based UI-logic isolation in WordPress is quite enough for many purposes...

If you still insist on using an MVC approach you can do it; WordPress MVC like plugins.

Argument 3 - WordPress is slow and it is not scalable for high-traffic web sites.

Not true.

Yes, WordPress is slower to render a page compared to your hard-coded PHP code, (due to additional process execution overhead). BUT if you are relying on your code rendering performance in order to high scalability, sorry, you don't know anything about scalability.

WordPress comes with a zillion caching and performance plugins that will deliver a better site performance that you can hardly match with your own effort.

Final conclusion;

I don't want to be the 3,434,533th developer to build a login/password recovery functionality for his/her web site. This is why I go for WordPress.

At the end of the day, our time is limited in this world.


One option to consider is setting up WordPress to serve your static pages (to avoid spending time reimplementing a CMS for this content) and using CakePHP to develop the dynamic application that is the core of what you're building.

You can then host them under the same domain, and if you set up the same page structure / CSS for both WordPress and CakePHP then it should be seamless to users.

A similar example I have is a site running WordPress for content management, and phpBB for a forum, both styled to look the same:

  • WordPress section
  • phpBB section

This does mean you have to maintain two page themes (CSS & HTML) and keep them in line with each other, but it does give the advantage of playing to WordPress's strengths of managing static content (about pages) and also time-based content (news articles) with a low time / effort investment, allowing you more time to concentrate on playing to CakePHP's strengths for your dynamic application that is the core of what you're building.

If you mostly use WordPress as it comes without doing much customisation / development, you should be able to get it running pretty quickly with a low learning curve, allowing you time to concentrate on your core application.


Here is an alternate solution for those wishing to embed a PHP application inside a WordPress page (thus leveraging all of the CMS goodies of WordPress without having to maintain multiple frameworks/themes). Basically, all you need to do is turn your application into a page template:

  1. Write you application sans support content (header/footer)
  2. Prepend the following code to your app: <?php /* Template Name: WhateverYouWant */ ?>
  3. Upload it to your /wp-content/themes folder
  4. Create a new page in WordPress and set the page template to WhateverYouWant


If you already have the database built, I would probably go with CakePHP because you are already proficient with CakePHP.

But if you are in the process of creating your database, you might want to look into using a WordPress plugin called Pods CMS, which creates custom tables of your own content (called "pods") inside of the WordPress database.

The Pods CMS plugin is heavily supported and there is also a plugin called Pods UI which works in the built-in WordPress Admin (to create an administration interface for the tables/"pods" content).

If you know a bit of PHP (arrays, objects, and loops) Pods CMS is easy to use and you often end up writing less code than if you are just working with the WordPress Codex. There are also helpers to let you write SQL that interacts with the existing WordPress table structure (pages, posts, categories, tags, etc.) which otherwise is a little complicated unless you really study the database.

WordPress also offers something called "custom fields", but this isn't often ideal as it just adds content into the existing WordPress tables. But custom fields work better with a lot of WordPress plugins (for things like feature sliders and widgets) if you really like using those kind of plugins.

All this being said, WordPress isn't the fastest and, depending on your setup (hosting, WordPress cache plugin) you could end up with a really slow site. If you do decide to go with WordPress I would try to get a hosting service that is recommended for WordPress and use a cache plugin to speed things up (like WP Super Cache).


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' => '<wp username>',
            'password' => '<wp password>',
            'database' => '<wp 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:

<?php echo $post; ?>

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


I think that for this project CakePHP is the best choice, because you already know how to deal with it and if you developed another web applications with it, you can grab some code from there for helping you with the user registration and maybe other parts, so you don't really have to build too much and you'll be able to focus on the main features of the new application.

If you want to learn WordPress more than developing your new app, go for WordPress. It's always good to learn new things.


use cakePHP as the framework and wordpress as the backbone


WordPress is not a framework, but a CMS. It gives you a system to manage content (content management system). If you do not have special needs regarding your application, WordPress may be the right choice.

If you need PHP pages to display dynamically loaded content, I think WordPress is not the thing for you. I suppose you already know how to build web applications with CakePHP, so why not use it? If you think you need a less complicated framework, I suggest Toro (it has nothing to do with frameworks such as Kohana or CakePHP; it is very simple).


Use WordPress to make your application, and contact WP-specialist bloggers to feature you as one of the "brave" ones to use WordPress. You could probably get a few good backlinks that way and some publicity.

Many people who back WordPress for any kind of website do so because they are highly invested in it (which happens when you spend a lot of time learning a technology). That's why you get a lot of strong opinions on questions like this. The way I see it, WordPress is just a compilation of a lot of PHP files, and if you know PHP, you know how to use that to your advantage. If it adds value (like you said, it has the membership functionality), without adding too much that is extraneous, then use it. Otherwise, keep it simple with CakePHP.


To me the best and the way that worked for me was given on the official WordPress documentation here

I just prepend this following piece of code on all the PHP pages of my application

<?php
require('/the/path/to/your/wp-blog-header.php');
get_header(); 
?>

And it worked without any glitches.

Also, if you want the WordPress footer, just append

<?php
get_footer();
?>

to those files.

Thanks to @Jesse for showing the way

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号