Include files in the codeigniter view

Asked

Viewed 163 times

0

Hello, I’m trying to call a js/css file that is inside application/views/app.js, but I’m trying to include it within a view that opposes in the same folder application/views/login.php but a 403 error is returned, someone has some solution for this?

EDIT

I found a helper that might help, it generates a hash calling the file but is still giving error 403

if (!function_exists('link_ng'))
{
    function link_ng($js = "")
    {
        $CI =& get_instance();
        $base_principal = $CI->config->slash_item('base_url');
        $version = hash("haval160,4" ,(date('YmdHis')));

        if ($js!='')
        {
            return "<script src='".$base_principal."app/views/{$js}?v={$version}' language='javascript' type='text/javascript'></script>";
    }
    return "";
}

}

2 answers

1

Hello! Error 403 is permission denied. You cannot and is not allowed to access directory files /application directly via a path in the URL. Files below the /application are unique for use of the Codeigniter framework.

To refer to a file as a javascript, create a directory /js brother of /application and assemble the address so if using your helper:

return "<script src='".site_url('js/'.$js.'?v='.$version)."' language='javascript' type='text/javascript'></script>";

Otherwise type the javascript script import directly into HTML:

<script src="<?=site_url('js/meu_javascript_monstro.js')?>" language="javascript" type="text/javascript"></script>

0


Good after so much searching in gringos forums I found a suitable solution, inside the folder application, the file .htaccess is in charge of blocking all direct requests to the files, this practice is not very recommended, and once used in the wrong way can leave loopholes in the system, follows the code that should be replaced by the content of application/. htaccess, if there is no create file:

# deny *everything*
<FilesMatch ".*">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# but now allow just *certain* necessary files:
<FilesMatch ".*\.(js|JS|css|CSS|jpg|JPG|gif|GIF|png|PNG)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

You can switch to accept other files, direct access to the view files . php for example will still be blocked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.