Welcome Guest, Not a member yet? Register   Sign In
Problem linking assets [solved]
#1

[eluser]Unknown[/eluser]
I am feeling really stupid now! I am just getting into CI, but for some reason I cannot for the life of me figure out what I am doing wrong while trying to link Javascript files. I have been searching the forums and trying different things. I have tried a couple of different things, from changing from absolute to relative links, relative to the front controller, relative to calling view (which I thought I remember being wrong, but tried it anyway), and I even used a couple of asset management helpers and plugins. Nothing has worked, which makes me think I am missing something major, and probably immediately evident to others.

Anyway, I just went back to trying to directly link them myself. Here is what I have now, which is what was suggested in several threads I found:

Code:
<!DOCTYPE html>
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        <scr+ipt type="text/javascript" src="&lt;?php echo base_url(); ?&gt;assets/jquery.js"></scr+ipt>        
        <scr+ipt type="text/javascript" src="&lt;?php echo base_url(); ?&gt;assets/page.js"></scr+ipt>
    &lt;/head&gt;
    &lt;body&gt;
        Testing.
        <div id="thing"></div>
    &lt;/body&gt;
&lt;/html&gt;

The jquery.js file is an uncompressed jQuery 1.7.2 file.
The page.js file is just a JS file with an alert in it being used to test.

The base_url set in my config.php file is: 'http://localhost/cijquery/index.php/' (I have not removed the index.php from the URL with .htaccess due to wanting to get this resolved first)

Here is the controller code calling this view:
Code:
&lt;?php
    class Users extends CI_Controller {
        
        public function __construct() {
            parent::__construct();
        }
        
        
        public function players() {
            $this->load->helper('url');
            $data['title'] = "CI Test Page";
            
            $this->load->view('players_view', $data);
        }
    }

//End of file

My folder structure is mostly how it unzips from the CI 2.1.0 zip file. I have one extra controller named users.php which can be seen above in its entirety, one extra view called players_view.php (also above), and a folder called "assets" (which contains the jquery.js and page.js files) on the same level as the application folder, system folder and the index.php file (I also tried moving the assets folder inside the application folder with no better results).

Here is the error I am getting in the Chrome Developer Console:

GET http://localhost/cijquery/index.php/assets/jquery.js 404 (Not Found) players:10
GET http://localhost/cijquery/index.php/assets/page.js 404 (Not Found) players:10

If someone could tell me what I am doing wrong, I would greatly appreciate it!
#2

[eluser]Samus[/eluser]
index.php is on the same level as /assets/ no?

your url indicates /assets/ is under index.php Smile

so your best bet would be to add the htaccess and remove index.php from your config e.g

Code:
$config['index_page'] = '';

or just don't use base_url() and type the full link out.
#3

[eluser]Unknown[/eluser]
[quote author="Samus" date="1334448764"]index.php is on the same level as /assets/ no?

your url indicates /assets/ is under index.php Smile

so your best bet would be to add the htaccess and remove index.php from your config e.g

Code:
$config['index_page'] = '';

or just don't use base_url() and type the full link out.[/quote]

Holy crap...I got so used to just not even thinking of index.php being there that it didn't even hit me that I was specifically saying index.php was over it instead of on the same level. I wasn't even seeing index.php, and it had just morphed into part of a domain name to me.

Well, just as I was hoping, it was something immediately evident to someone else, haha! That fixed it, of course! Thank you very much!




Theme © iAndrew 2016 - Forum software by © MyBB