Integrating Serendipity Blog Framework with Codeigniter

By Craig Collins at

Integrating Serendipity Blog Framework with Codeigniter

s9y's Serendipity blogging framework supports an embedded mode so that it can be inserted into your existing web site.  But what about a site using CodeIgniter's MVC framework?

Embedding the Serendipity blog is explained fairly well here. We modify that method slightly so that the blog.php file that you create contains the following:

<?php
   ob_start();
   chdir("../www/blog");
   require("index.php");
   global $contents;
   $contents = ob_get_clean();
   chdir("../");

Next, the controller name matches the subdirectory that the blog is installed in. For example, a site which uses /blog would create a controller named Blog. This controller would contain the following code OUTSIDE of the the class definition (but within the file)

global $contents;
require_once("[Path to your blog.php file]");

Lastly, the serendipity contents can be accessed within your controller by accessing the $contents global:

    public function index() {
       global $contents;
       global $serendipity;
      

You will notice I also have a reference to the serendipity global variable. The serendipity global is used to pass information around within the serendipity blog framework and with the method above it is then completely accessible within your controller.  The result is an integration that works unexpectedly well...not just on the surface but within the PHP code, as well.

 
0 Comments

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Leave A Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

About This Blog

This blog is a place to read about the latest news and activity going on at McNee Solutions

Categories