Welcome Guest, Not a member yet? Register   Sign In
site_url() vs $CI->config->site_url()
#1

[eluser]ebynum[/eluser]
My path to discovering this "problem" was fairly strange, so I'll elaborate a bit.

I am working on a site that has a CI installation in the web root and a WordPress blog installed in the /blog folder. In order to use the WordPress "Loop" to display posts and other information within the CI context, we include the WP "header" into the index.php file that is running CI with:
require('blog/wp-blog-header.php');

WP does a lot of things, including defining a site_url() function that serves the same purpose as CI's site_url() function, but which points to the site_url for the WP install (in this case, /blog).

The problem that I discovered as a result is this:

form_helper.php makes reference to the site_url in several locations, including form open. It uses $CI->config->site_url() to build its site_url() relative links.

url_helper.php defines the site_url() function (if it can), and then uses it internally instead of just referring to $CI->config->site_url(), even though all of the relevant functions (redirect and anchor in particular) are already pulling a reference to $CI.

Is there any good reason for the definition of (and internal use of) site_url() in the url_helper helper?
#2

[eluser]xwero[/eluser]
Are you saying you use WP inside CI and because of this the WP site_url function is used instead of the CI site_url function in functions like anchor and anchor_popup? And this is why you propose to use $CI->config->site_url() in every url_helper function?

CI and WP are not really meant as mixed environment frameworks/applications. The helper functions are a bigger problem because CI's helper functions are extendible but they have no prefix to distinguish them form a function with the same name coming from somewhere else.
Too bad php5.3 adaptation is still a long time away because the prefix is only a substitute for namespaces. Which will make function name collisions less likely because then you can do WP\site_url and CI\site_url.

Using the $CI->config->site_url() would be a solution for the current problem but i guess the EL developers choose to make the url helper functions as less dependent on CI as possible although a newly added function, current_url, uses $CI->config->site_url() and $CI->uri->uri_string() where it could used site_url and uri_string().
I wonder how the developers at EL look at mixed environment CI code?
#3

[eluser]ebynum[/eluser]
Yes and no. I understand that any problems being caused by using CI and WP side-by-side are my own to deal with.

My question was simply about why the url_helper used an internally-defined function
Code:
site_url()
(that it internally acknowledges may not be definable [with the call to
Code:
if ( !function_exists() )
]) to perform an action instead of using the function at
Code:
$CI->config->site_url()
that it knows exists.

I understand making
Code:
site_url()
available in the helper - but don't see any good reason for the other functions inside of url_helper to be dependent on it. It doesn't seem to add anything (other than possibly letting you redefine the site_url() for all of those functions simultaneously) and opens up the possibility for problems (as I discovered).
#4

[eluser]xwero[/eluser]
the check it added to make it possible to overwrite the function, by ceating a function with the same name in the MY_url_helper.php file, so when someone does overwrite that function the other functions will have the same behavior.

For example the site_url function gets overwritten to add a language segment in front of the uri. Then the anchor function will have that language segment too.

I wrote about the current_url function using helper functions instead of CI methods but for that function it's bad to use overwritten functions.
#5

[eluser]123wesweat[/eluser]
@ebynum, i am having a bit of a problem too with WP + CI.

i added
require_once './blog/wp-load.php';//WP

to the index.php to have WP enabled in my CI pages/website.

But know i notice my breadcrumbhelper doesn't work anymore (and i am a bit afraid to check which
other helpers don't work)

How did you solve the site_url() issue?




Theme © iAndrew 2016 - Forum software by © MyBB