Reputation: 91
i'm developing a website. I would like to use Wordpress to create homepage and other pages, and Codeigniter to create other. What is the best way to do this? So, for example:
http://mysitename.com/ => Go to WORDPRESS Homepage.
http://mysitename.com/animals/cat => Call the cat function in animals controller in CODEIGNITER.
http://mysitename.com/contact => Go to WORDPRESS Contact page.
How could i realize that? Is it possible? For example, could i show Wordpress page using it as view in Codeigniter Controller?
Thank you in advance
Upvotes: 1
Views: 2026
Reputation: 745
You need to create wordpress as primary :
Add the WordPress index File
require_once('/Server/path/to/wp-load.php');
require_once BASEPATH.'core/CodeIgniter.php';
Extend Codeigniter URL Helper
create a new namespaced function 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.
Change site_url to ci_site_url in CodeIgniter App
Quick search your applications, controllers, models, and directories and replace all site_url file references with ci_site_url.
WordPress stopping Contorting from Cookies
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. In line no. apprx 520
function ci_ignore_magic_quotes($value,$key)
{
if($key != "ci_session")
{
stripslashes_deep($value);
}
}
Comment out the following lines inside the wp_magic_quotes function and add a reference to the ci_ignore_magic_quotes function.
array_walk($_COOKIE, 'ci_ignore_magic_quotes');
//$_COOKIE = add_magic_quotes( $_COOKIE );
Additionally, you will have to set WordPress to not unset the $_COOKIE['ci_session']:
$no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', \\
'_SERVER', '_ENV', '_FILES', 'table_prefix','ci_session' );
you can start using WordPress with your CodeIgniter application like as usually in use.
More Tutorials : https://gist.github.com/philbirnie/4674643
https://www.cometchat.com/blog/how-to-integrate-codeigniter-with-wordpress/
Upvotes: 2