Welcome Guest, Not a member yet? Register   Sign In
Maybe you can help, Global variables?
#1

[eluser]richfearless[/eluser]
I have a strange request, I deploy my applications on both Windows & Linux, and i have been confronted by an error in my code, across my site i use this method
Code:
<a href='&lt;?=base_url()?&gt;this/is/a/link'>blah</a>
to set links.

Now for some strange reason my AJAX goes wonkyup on Windows using ISAPI_REWRITE.
So i need turn off those pretty urls and add index.php to the end of &lt;?=base_url()?&gt; but for link-usage only, keeping images that use baseurl happy too Big Grin

so what my question boils down to is, how do i setup a global variable similar to base_url() but with a different name & value.








-thanks
#2

[eluser]pistolPete[/eluser]
You could use a custom config file: http://ellislab.com/codeigniter/user-gui...onfig.html
#3

[eluser]InsiteFX[/eluser]
Hi,

Code:
you have

<a href='&lt;?=base_url()?&gt;this/is/a/link'>blah</a>

should be

<a href='&lt;?=base_url();?&gt;this/is/a/link'>blah</a>

Your missing the semi-colon

As far as adding your own just add it to the config.php file or you can do it like this in constants.php these are submitted by users on this forum so no credit to me.

Code:
/*
|--------------------------------------------------------------------------
| Docment root folders
|--------------------------------------------------------------------------
|
| These constants use existing location information to work out web root, etc.
|
*/

// Base URL (keeps this crazy sh*t out of the config.php
if (isset($_SERVER['HTTP_HOST']))
{
    $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
    $base_url .= '://'. $_SERVER['HTTP_HOST'];
    $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);

    // Base URI (It's different to base URL)
    $base_uri = parse_url($base_url, PHP_URL_PATH);

    if (substr($base_uri, 0, 1) != '/')
    {
        $base_uri = '/'.$base_uri;
    }

    if (substr($base_uri, -1, 1) != '/')
    {
        $base_uri .= '/';
    }
}
else
{
    $base_url = 'http://localhost/';
    $base_uri = '/';
}

// Define these values to be used later on
define('BASE_URL', $base_url);
define('BASE_URI', $base_uri);
define('APPPATH_URI', BASE_URI.APPPATH);
define('ASSETS_URL', BASE_URL."assets/");
define('IMAGES_URL', ASSETS_URL."images/");
define('CSS_URL', ASSETS_URL."css/");
define('JS_URL', ASSETS_URL."js/");

// We dont need these variables any more
unset($base_uri, $base_url);

Enjoy
InsiteFX
#4

[eluser]Chad Fulton[/eluser]
This seems very odd to me. I would suggest you figure out how to fix the ISAPI_REWRITE problem with AJAX, since it may kick up other bugs at some point.

However, if you really want to do it this way, then I suggest extending the URL Helper to have a new function that does what you want. It could be called something like index_url()

Here's how you might do it (although, if you don't have a firm grasp of extending helpers, you might check out that link above anyway!):

application/helpers/MY_url_helper.php
Code:
function index_url() {
    return base_url().'index.php/';
}
#5

[eluser]Chad Fulton[/eluser]
Or, you could do it one better, and essentially overwrite the base_url() function to accept a parameter, which would tell it whether or not to append the index.php part. This would probably be the best option, because if you fix the ISAPI_REWRITE problem, then you could simply remove the MY_url_helper.php file and all of your links would automatically use the normal base_url() function without having to change a thing.

Code:
// Note: most of the code in this function is copied directly from
// the original CI base_url() function
function base_url($append_index = false) {
    $CI =& get_instance();
    $base_url = $CI->config->slash_item('base_url');
    if($append_index) {
        $base_url .= 'index.php/';
    }
    return $base_url;
}

Then, you'd call it like this:

Code:
<a href="&lt;?= base_url(true); ?&gt;this/is/a/link">A link</a>

of course, this won't affect the functions site_url(), current_url(), index_page(), etc.
#6

[eluser]n0xie[/eluser]
Show us your httpd.ini. The problem probably originates there.
#7

[eluser]wiredesignz[/eluser]
Links should be using site_url() not base_url().
#8

[eluser]richfearless[/eluser]
What is the dif? can site_url be set anywhere?




Theme © iAndrew 2016 - Forum software by © MyBB