CodeIgniter + Wordpress integration

2019-01-16 11:55发布

My website is designed with Wordpress. Some theme pages have a custom made PHP script for booking things, which I want to refactor in CodeIgniter, to get more flexibility. Questions :

1) how to use CI functions in WP with CI's routing system ? Do I have to make a CI page index.php/controller/page1/ and then call it in Wordpress ?

2) Do I have to use CodeIgniter "views" system or Wordpress "theme pages" to get my result ?

Thanks

3条回答
你好瞎i
2楼-- · 2019-01-16 12:22

If you have an CI application that uses login session you have to modify the "load.php" file (from "wp-includes" WP folder). To do that follow the PhilB's answer from this link. For a complete explanation follow this post.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-16 12:28

WordPress and CodeIgniter both are the most popular framework in PHP. CodeIgniter is a lightweight PHP framework that can help in developing applications that can be integrated with WordPress.While some users prefer developing the CodeIgniter and WordPress elements separately, we will go through an example where the primary navigation and footer are similar on both platforms, because it doesn’t make much sense to update the navigation and footer twice.

Here we learn about two things using WordPress and CodeIgniter

  1. How to integrate already running WordPress website to integrate CodeIgniter
  2. How to integrate already running Codeigniter website to integrate WordPress

  3. Integrate CodeIgniter into WordPress It comes as a meager shock that numerous site proprietors overseers still lean toward WordPress as their essential Content Management System (CMS), and you can’t point the finger at them considering the far-reaching highlights that WordPress brings to the table.

Okay, let’s start to integrate CodeIgniter into WordPress here, WordPress is our primary application and we will use its functionality within CodeIgniter while keeping the CodeIgniter app in a sub-directory.

Step 1: Adding the WordPress Bootstrap File WordPress’s wp-load.php file immediately preceding the call to Codeigniter bootstrap file in CI’s index.php file

Before adding any WordPress functionality to CI’ file.we will testing to make sure everything works fine.The first page of our app looked fine, but that was about it.

Every URL within our app, including form handlers, were redirected to the root directory (i.e. WordPress’ directory), resulting in 404 errors. We discovered that both WordPress and Codeigniter have a “site_url” function in global scope. By loading the WordPress bootstrap file before CodeIgniter, we were getting WordPress site_url.Codeigniter function “failed” silently because it was checking to see if a site_url function existed.

Step 2: Extending Codeigniter URL Helper Our solution was to ‘extend’ the URL helper of CodeIgniter. By using ci_site_url, we can resolve the site_url issue. The My_url_helper.php (helper) file should be in the application directory of CodeIgniter.

Step 3: Change site_url to ci_site_url in the CodeIgniter App. Replace all site_url file references with ci_site_url into your applications, controllers, models, and directories.

Once we completed these steps, our CI app worked …

Step 4: Stop WordPress from managing our cookies! Our site that still was not working was the admin panel that we built in Codeigniter.our credentials have been accepted but, still redirecting to login page.

I think you know about CodeIgniter will create cookies for every active database session when you log in. This can lead to WordPress bootstrap file rectifying the issue. This happens when WordPress loops via the $_COOKIE global and implements add_magic_quotes functionality to all elements, except the CodeIgniter cookie.

  1. Integrate WordPress into CodeIgniter IF you have already created website in CodeIgniter and you have added blog page then WordPress is the best option so, First of all, install WordPress in a folder called the blog on your website. It would be located in the top level directory in your CodeIgniter website. So it would be alongside the system folder of the CI installation. If you already have a DB for your site, have WordPress add tables to that same DB with a prefix to make things simple.

After, that add the following line in the at the top of your CodeIgniter’s index.php file.Change the path to wp-blog-header.php as needed to point to your WordPress root directory.

All done!! This code allows to WordPress blog without leaving CodeIgniter site. More helper function explains in details in WordPress documentation.

View more: How to Integrate CodeIgniter with WordPress

查看更多
你好瞎i
4楼-- · 2019-01-16 12:40

I used the following.

My goal is to use CodeIgniter for some pages, and leave the other pages in Wordpress untouched. I only have a few steps to do it :

Copy CI folder at the Wordpress root

Modify the « index.php » of CI to add an include which will add WP functions to CodeIgniter :

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

Once this line added, Wordpress functions will be usable in CodeIgniter ; they will be used mainly for views.

Modify the .htaccess of WP to not rewrite CI's URLs : After this line :

 RewriteRule ^index\.php$ - [L]

Add this line :

RewriteCond %{REQUEST_URI} !^/(codeigniter_folder|codeigniter_folder/.*)$

Then CI views can use WP functions.

查看更多
登录 后发表回答