Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter App integration with Wordpress
#1

[eluser]Unknown[/eluser]
Hi,
I used codeigniter's sample CRUD program from the following URL : http://henrihnr.wordpress.com/2009/04/26...plication/.
It is working well in my local machine (xampp 1.7.7. under windows xp).

As a next step, i was trying to integrate the same into wordpress for which i was trying the following url.

http://www.bluelayermedia.com/wordpress-...ntegration

As stated in the url, I replaced the wordpress index.php file as codeigniter one.

Next, modified the index.php (Codeigniter bootstrapper) and wp-load.php file (wordpresses bootstrapper) as follows:

======================================
require_once 'wp-load.php';
require_once BASEPATH.'core/CodeIgniter.php';


/* End of file index.php */
/* Location: ./index.php */
=======================================

After which i tried accessing my localhost URL as http://localhost/wp

The CRUD program first page is displayed fine. But it looks plain codeigniter style and not utilising any theme of wordpress.

I am unable to retrieve other pages like view, update, delete, add new data by using this URL : http://localhost/wp/person/view/1

I have placed all the codeigniter folder under wp as follows:
===================================

/wp
|-/application
|-/system
|-index.php(cI)with wordpress bootstraph
|-/wp-content
|-/wp-includes
|-/wp-admin
====================================

I am unable to figure out the integration part with wordpress and grateful to the community for any advise / right resource pointer in this regard.
Thank you for your time.

Regards
#2

[eluser]jjDeveloper[/eluser]
try this instead as it will enable you to use CI in your themes. What it actually does is bootstraps CI into wordpress and not the other way around.

add this to
wp-content/themes/yourtheme/functions.php

Code:
function codeigniter_bootstrap() {
    require_once( 'index.php' );
}

add_action( 'template_redirect', 'codeigniter_bootstrap' );

then you have to add this piece in one of your template files ie page.php

Code:
$_GET['/wordpress/'] = null;
end($_GET);
require_once( dirname( ABSPATH ) . '/index.php' );
$CI = &get;_instance();
$CI->load->model('tstModel');
print_r($CI->tstModel);
die;

models/tstModel.php

Code:
<?php
/*
* test wordigniter
*/

class TstModel extends CI_Model
{
  var $data = array();
  function __construct()
  {
    parent::__construct();
    $this->data['tst'] = 'here would be some return content from codeigniter';

  }
  // Code...
}

now codeigniter will initialize and you can use it's classes. Here I am simply returning data from a codeigniter model that I can now use as data in wordpress.

I did this a while ago and have not tested it in CI 2.0 but give it a shot anyway as I'm sure there is a workaround if it doesn't.

#3

[eluser]CroNiX[/eluser]
Just beware that wordpress also has a site_url() function, which will override CI's since we have to load wordpress before CI (and everything, like anchor(), in CI that relies on it). If your wordpress is not in the same directory as ci, site_url() will point to wordpress location.

It's one reason I wished CI would prefix all of their functions. It would be redundant, but you would be able to integrate just about any other software in it which would make it a more usable framework.
#4

[eluser]Unknown[/eluser]
Working on similar problem here. Have already written application in CI, that I would like to import into wordpress, because there are few libraries that would change during time, and it would be pita to change twice.

@jjDeveloper
Seems like a fair idea, but what about routing rules ?

What is content of page is defined with url that codeigniter is parsing.

To make it more clear.
My problem is that CI is doing URL analyzing, and based on results (not related to routing)
it loads page content and all other details (using API)

My problem at the moment is that part of code should be included in every call (menu generation, etc)
but in certain cases last call (page content for example)
should be left out if that is wordpress content.

I'm stuck on this for couple of days now, and it real pain in the ass to make it all work together as planed.

Does anyone have any idea ?

I even thought about overwrting CI_Router so CI is aware of page that has been loaded, and based on that it initializes rest of the laoding process or breaks it.

Anyone with similar problem, and better solution ?

Tnx ppl.

#5

[eluser]DanSearle[/eluser]
Shame this thread died Sad

I'm in the same as CimbaljevicN - I have a WP site, I want WP to handle URL parsing, but I need CodeIgniter to handle some form submissions via POST, and to produce some content that can be shown in certain WP page templates that I'll define in my WP theme.

I'm using this WP plugin to enable CI: http://wordpress.org/extend/plugins/wp-code-igniter/

but CI is handling the URLs before WP gets them - so if you follow a link to a WP page, e.g. www.mysite.com/general/latest-news then CI throws a 404 because there's no controller for that page.

Ideally I'd like CI to handle URLs that it can, and pass any that it can't on to WP - so it's up to WP to throw a 404 if it can't resolve the URL.




Theme © iAndrew 2016 - Forum software by © MyBB