Question

I'm having trouble with the path when a file calls a css or a js file.

I'm using Codeigniter also Smarty template engine. My base URL is> http://local.project

My css and js files are located in> project/site/assets/css and project/site/assets/js

The thing is that when I call the resources from the view the path is a mess and not found error appears.

I have tried many ways but still can't make it. I begin to think that this can be a path problem from Codeigniter. I mean.. maybe I'm missing something that I can't figure what is.

When I do an inspection with the browser I can see that this is set by default> http://local.project/

and then from the view I call it like>

<script type="text/javascript" src="{site_url()}assets/js/jquery.flot/jquery.flot.js"></script>

but the path that is built is>

http://local.project/%7Bsite_url()%7Dassets/js/jquery.flot/jquery.flot.js 400 (Bad Request) 

I'm driving crazy here, any help would be very appreciated!

Was it helpful?

Solution 5

I could make it. Just opened my Smarty.php file and changed this line view/admin just to views

        $this->setTemplateDir(APPPATH.'views');

After that the url I could use from the view is

<script type="text/javascript" src="assets/js/jquery.flot/jquery.flot.js"></script>

OTHER TIPS

try:

<script type="text/javascript" src="/assets/js/jquery.flot/jquery.flot.js"></script>

or

<script type="text/javascript" src="/js/jquery.flot/jquery.flot.js"></script>

can you provide your ip,to view the page?

Try using base_url() instead of site_url().

try:

<?php
    echo "<script type='text/javascript' src='" . base_url() . "assets/js/jquery.flot/jquery.flot.js'></script>" ;
?>

To use the base_url() you need to call in your controller the URL helper:

$this->load->helper('url');

Then in your view:

<script type="text/javascript" src="<?php echo base_url();?>assets/js/jquery.flot/jquery.flot.js"></script>

First of all load the url helper

$this->load->helper('url');

secondly get base address using this

echo base_url();

and finally your base address is "http://local.project", no slash at the end, so try this

<script type="text/javascript" src="<?php echo base_url();?>/assets/js/jquery.flot/jquery.flot.js"></script>

and make sure your base address do not have any extra characters, like space or enter

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top