0

I designed a site using Wordpress, and have been trying to get a Codeigniter form app integrated with it, with all the corresponding URLs.

I put the CI app in the root folder of the Wordpress site. The folder is named "Chile" (it's a series of forms separated by LATAM countries). I changed the .htaccess file to include /chile where necessary. I also added:

require '../wp-load.php';

to the CI index.php file.

I can now load some of the essential urls in the CI app, but they don't seem to be routed properly.

the base url is set to:

$config['base_url']  =  "http://".$_SERVER['HTTP_HOST'];

$config['base_url'] .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])).'/';

the site is www.dermusikplatz.com. the form is located under www.dermusikplatz.com/chile/applications which i can reach by manually entering that. but when i try to submit the form, the url appears strangely as www.dermusikplatz.comapplications/save. In general, the urls constructed by the controllers and views just don't seem to be set up properly.

I've looked up the documentation regarding routing and have tried creating a $route rule. but i'm not sure what to route from and to what exactly. I've also seen various threads that suggest using MY_URL_helper to change the value of 'site_url' to 'ci_site_url', to avoid any redundancies between the value that Wordpress and CI have for that, but i'm not sure where to even start with that, even after checking out the helper documentation.

I've also tried going in and changing each path value in statements like these from:

$this->load->view('applications/form');

to:

$this->load->view('/chile/applications/form');

but I understand that makes little sense as that directory doesn't exist. I assumed that changing the .htaccess file and the base_url would cover it, but there seems to be much more to it than that.

I'm a little lost here, and not super familiar with Codeigniter.

If anyone can help set me in the right direction at the very least, I would really appreciate it. Thanks.

  • I've never actually done this, but looked into it once, and I remember specifically thinking I would prefer to set up CI to nest Wordpress, rather than the other way around. Maybe I was wrong, I don't recall details - but might be worth looking at before you dive too far into this. I've set up both separately numerous times. – TCooper Nov 01 '19 at 23:59
  • did you check this? https://stackoverflow.com/a/18105075/2275490 – Vickel Nov 02 '19 at 00:21
  • @Vickel yes, i did. thank you. i followed the steps in the primary answer already. – elpretentio Nov 02 '19 at 01:57
  • If you are able to load the view in your application then possibly your setup is right. This may be just the workaround but not a solution, can you replace `$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];` to `$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";` and try? – Akshit Arora Nov 02 '19 at 08:56
  • thanks for the feedback. when i try to add . "/" or . "/Chile/" (as noted below in the answer), it just seems to break the views. they appear with no styling. and it doesn't fix the issue with the Controllers routing. in the .htaccess file for CI, i added these rules already: ```RewriteRule ^index\.php$ - [L] RewriteEngine On RewriteBase /chile/ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/chile/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]``` – elpretentio Nov 04 '19 at 18:06
  • @AkshitArora those .htaccess rules seem to work for the views but not the Controller. i appreciate your suggestions, but the issue persists. – elpretentio Nov 04 '19 at 18:11

1 Answers1

0

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];

Change that to:

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'] . '/Chile/';

It is worth noting that if you are hosting on Linux the 'Chile' must be the exact same case as your folder is called. So, if it is 'Chile', do not call it 'chile'

Kobus Myburgh
  • 1,114
  • 1
  • 17
  • 46
  • thanks for the feedback. when i try to add . "/" or . "/Chile/" it just seems to break the Views. they appear with no styling. and it doesn't fix the issue with the Controllers routing. in the .htaccess file for CI, i added these rules already: ```RewriteRule ^index\.php$ - [L] RewriteEngine On RewriteBase /chile/ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/chile/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] ``` – elpretentio Nov 04 '19 at 18:12
  • those .htaccess rules seem to only help the Views load, and the changes I have tried with base_url don't seem to be working. – elpretentio Nov 04 '19 at 18:13
  • I can't say for sure, but changing the base_url will break your CSS and things if you hard-coded your paths to load your CSS. If you, for example, load your CSS from `"/Chile/whatever.css"` and your base_url now contains the `/Chile/` part, then it will break. You need to ensure that the paths to your CSS and scripts are still correct after changing the paths.Best would be to use the `base_url()` function to set the path relative to your CSS files, .e.g, `src="css/styles.css"` or whatever your path is. – Kobus Myburgh Nov 05 '19 at 21:35
  • Oh, and where you load the views, use the `base_url()` function as well, as I suggested above. My suggestion about what to do with the base_url is definitely correct.Hard-coding paths makes your site not portable. – Kobus Myburgh Nov 05 '19 at 21:37
  • i discovered the issue. it was removing the ```require '../wp-load.php';``` line in index.php. it was overriding site_url. i thought it was essential to integrating with WP, but apparently not. – elpretentio Nov 06 '19 at 17:54
  • You could rename the CI version of the function to something like `ci_site_url()` - so create a new helper, and then create a function that has the same content as the original `site_url()` helper function. But if you don't need wp_load, then I guess it does not matter :-) – Kobus Myburgh Nov 07 '19 at 19:50