Giter Site home page Giter Site logo

Comments (9)

dynamodan avatar dynamodan commented on July 26, 2024

Alright, this depends on some careful cooperation of the WordPressIgniter settings and CodeIgniter's config/routes.php settings. Since both WordPress and CodeIgniter each have their own 404 handling methods, they both need some attention. In the plugin settings, there are two checkboxes: "Divert 404s to WordPressIgniter" and "CodeIgniter grabs all SEO urls (use with caution!!)".

"Divert 404s to WordPressIgniter" UNCHECKED:
Any url that WordPress can't resolve gets the WordPress 404 page rendered out, even if it was a valid CodeIgniter url. If it was a valid CodeIgniter url, that CodeIgniter url and route gets executed normally, but the user is still shown the WordPress 404 page, whatever it may be in the configured template, etc.

"Divert 404s to WordPressIgniter" CHECKED:
Any url that WordPress can't resolve gets the CodeIgniter output rendered out using the configured Page Override page.

"CodeIgniter grabs all SEO urls" UNCHECKED:
The plugin caches the contents of $_SERVER['REQUEST_URI'] and temporarily sets it to '/' to force CodeIgniter to load its default controller and index function. By default this is 'welcome/index'. CodeIgniter's routing is doing practically nothing in this case. Using this setting unchecked makes CodeIgniter pretty useless unless you have everything happening in the default controller's index function, or maybe you're doing routing with the url parameters the old fashioned way etc.

"CodeIgniter grabs all SEO urls" CHECKED:
Here's where things get the most useful. But, you must have a sort of a "do nothing" 404 override set in your config/routes.php. This function will get called every time a WordPress post, category, or anything is accessed by a SEO url. If you have this setting checked, but no $route['404_override'] set, then CodeIgniter's 404 page will show even on valid WordPress urls (because they're not valid CodeIgniter urls!!).

Sorry if I'm not good at explaining, some of this you're probably going to need to experiment with yourself, but trust me I've spent many long hours with lots of different methods to arrive at what we have now. Probably the bottom line understanding is that when the plugin is enabled, CodeIgniter ALWAYS runs. Depending on those two settings described above, and the configuration in config/routes.php, CodeIgniter WILL do one of these 4 things:

  1. Run the default controller and function set by $route['default_controller']
  2. Run the controller and function determined by the url path.
  3. Run the "catch all" controller and function set by $route['404_override']
  4. Show its own 404 error, completely overriding WordPress

Again, with this plugin enabled, CodeIgniter WILL do one of the 4 things above, even if its output isn't rendered out to the user. This theoretically can result in some special circumstances. Say you have a path collision, perchance that you have a CodeIgniter controller and method (or custom route) that responds to /categories/uncategorized . The specific CI controller and method will run, even though WordPress renders out its own category view. This is for two reasons: 1. It wasn't a WordPress 404 and 2. It wasn't a CodeIgniter 404. So just be careful to avoid this kind of CodeIgniter routing collisions (unless you really intended it).

from wordpressigniter.

netsenior avatar netsenior commented on July 26, 2024

Hey Dan

thanks for the explanation, and for the good job. I will expriment those options carefully later.

cheers

from wordpressigniter.

ansmn1974 avatar ansmn1974 commented on July 26, 2024

Dear Dan,
Thank you for the great plug-in. I just wanted to inform you of a bug:

I created the controll sum.php that has the function my_sum($a,$b)

I wanted to try to call a controller with parameters .
I called it from the url: http://localhost/wp/sum/my_sum/1/2/

I got the result that is shown in the image
screen shot 2014-09-01 at 19 30 00

It shows that it throws an < h1 > tag with the word wordpressigniter in it
Source code that being rendered by the browser is like the following:
< h1 class="entry-title">WordPressIgnition!

But thank you for the nice plug-in

from wordpressigniter.

dollardad avatar dollardad commented on July 26, 2024

Thanks for this great plugin, just working my way through the code.
Some useful tips for anyone wanting to use this.

  1. All WordPress functions, hooks and filters are available to you in your Codeigniter Controllers and Models.
  2. You can use either or both $db (need to setup your database ci config as usual) and $wpdb ( global $wpdb). Really handy if you want to keep database code in two tables.
  3. You must remove headers and footers in you ci views ( use the wordpress template system ).
  4. You can enqueue scripts through either your wp theme or CI app.

from wordpressigniter.

superlaziale75 avatar superlaziale75 commented on July 26, 2024

Dear Dan,

Great job!

could you please help us to understand what do you mean when you say "have a sort of a "do nothing" 404 override".
How can do that?
How can redirect the WP URL to WP?

Thank you very much.

from wordpressigniter.

hakimny avatar hakimny commented on July 26, 2024

@dollardad , @dynamodan

How did you manage to use wordpress functions in CI, i tired calling them directly , they do not generate an error but i have no output.

Any help on this would be highly appreciated.

thx
Hakim

from wordpressigniter.

dynamodan avatar dynamodan commented on July 26, 2024

It could be a problem with output buffering. I tend to use logging to tackle this kind of problem. Can you write something to a log to see what the functions are doing, i.e. by assigning their return value to a $variable and then echoing it to a log? I know your hosting may not give you very ready access to the logs but I depend heavily on logging in most aspects of my work. :)

from wordpressigniter.

dynamodan avatar dynamodan commented on July 26, 2024

@superlaziale75

Think of CodeIgniter always running even if it's not a match for the currently loading page in WordPress. It will throw its own internal 404 error on every page that doesn't match a CodeIgniter route. You just won't see anything on pages that WordPressIgniter doesn't catch as a CI-integrated page. I'm more comfortable knowing exactly where CodeIgniter's execution path will go in those situations so I like to use a "catch all, do nothing 404 page".

from wordpressigniter.

dynamodan avatar dynamodan commented on July 26, 2024

@ansmn1974

You are probably echoing the function's output. Try assigning the function's return value to the $CI_OUTPUT global variable. (Remember to say global $CI_OUTPUT in your function.)

from wordpressigniter.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.