Welcome Guest, Not a member yet? Register   Sign In
HTML Helper and Javascript issues
#11

[eluser]TheFuzzy0ne[/eluser]
What does your "terribly convoluted .htaccess" look like?
#12

[eluser]korukyu[/eluser]
The .htaccess code looks like this:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|user_guide)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

I tried moving the js folder to the controller folder so that when I try to navigate from my main controller into /js/java.js, it would be easier. But still no luck. I can't get my pages to find the darn file.
#13

[eluser]TheFuzzy0ne[/eluser]
Add any other directories you want to allow access to, to this line:
Code:
RewriteCond $1 !^(index\.php|user_guide)

If you're folder is named "js", it should look like this:
Code:
RewriteCond $1 !^(index\.php|user_guide|js)

Now let's say you wanted to add 2 new directorys, images and css, you'd do this:
Code:
RewriteCond $1 !^(index\.php|user_guide|js|images|css)

However, I'd recommend scrapping that version, and going with this version, which will direct the the requested directory if it exists, or redirect the request through CodeIgniter if it doesn't. Just don't name any controllers the same as the directories in your Web root, otherwise the controller will never be called. Tongue
Code:
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

This will save you having to add any directories to your htaccess file.

EDIT: Whoops! Forgot to add the lines to stop users accessing your system directory.
#14

[eluser]korukyu[/eluser]
Hm, for some reason that .htaccess gives me an error. The main controller works fine at my localhost/CI, but anything below that gives me a 'URL not found on this server' error. If I try to navigate to my 'test' controller (localhost/CI/test) it now says 'The requested URL /index.php/test was not found on this server.'

fiddling with the index page setting in the config file has no effect, but since we're using the mod rewrite I just left it blank... So now along with not being able to find my js file, it also can't find the rest of my site? I am clearly doing something wrong...
#15

[eluser]TheFuzzy0ne[/eluser]
Is the 404 error the default server one or the nicely formatted CodeIgniter one?

Please try this htaccess instead:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

EDIT: It's probably not something you did wrong, but rather something I did wrong.
#16

[eluser]korukyu[/eluser]
Thanks, it's working again now, though it's still not finding the javascript file. I'll keep working on that. Thanks for the help.
#17

[eluser]superwad[/eluser]
Here's one that I modified from link_tag() and works:

Code:
/**
* Script
*
* Generates link to a script file
*
* @access    public
* @param    mixed    script src or an array
* @param    string    type
* @return    string
*/
if ( ! function_exists('script_tag'))
{
    function script_tag($src = '', $type = 'text/javascript', $index_page = FALSE)
    {
        $CI =& get_instance();

        $link = '&lt;script ';

        if (is_array($src))
        {
            foreach ($src as $k=>$v)
            {
                if ($k == 'src' AND strpos($v, '://') === FALSE)
                {
                    if ($index_page === TRUE)
                    {
                        $link .= 'src="'.$CI->config->site_url($v).'" ';
                    }
                    else
                    {
                        $link .= 'src="'.$CI->config->slash_item('base_url').$v.'" ';
                    }
                }
                else
                {
                    $link .= "$k=\"$v\" ";
                }
            }

            $link .= ">&lt;/script>";
        }
        else
        {
            $link .= 'type="'.$type.'" ';

            if ( strpos($src, '://') !== FALSE)
            {
                $link .= 'src="'.$src.'" ';
            }
            elseif ($index_page === TRUE)
            {
                $link .= 'src="'.$CI->config->site_url($src).'" ';
            }
            else
            {
                $link .= 'src="'.$CI->config->slash_item('base_url').$src.'" ';
            }

            $link .= '>&lt;/script>';
        }


        return $link;
    }
}

$src can be either a full URL (http://www.example.com/script.js), a relative path (inc/script.js), or an array like:

Code:
array('src'=>'script.js',
'type'=>'text/javascript')

$type is optional, and defaults to 'text/javascript', although you can override if you want.
$index_page is optional, and defaults to false. Setting it to true will cause $config['index_page'] to be inserted into the URL generated (if a relative URL).

I've tested it and everything works for me (using 1.7.1), so hopefully somebody else out there finds it useful Smile




Theme © iAndrew 2016 - Forum software by © MyBB