Welcome Guest, Not a member yet? Register   Sign In
where to put include jquery?
#1

[eluser]obay[/eluser]
I'm trying to use JQuery with CodeIgniter. I've googled a bit all the examples were complicated.

I just want to know, where is the best place to put a line such as this?

Code:
[removed][removed]

In each view? In a common view?
#2

[eluser]jdfwarrior[/eluser]
[quote author="obay" date="1252949735"]I'm trying to use JQuery with CodeIgniter. I've googled a bit all the examples were complicated.

I just want to know, where is the best place to put a line such as this?

Code:
[removed][removed]

In each view? In a common view?[/quote]

Depends on how your stuff is structured.
#3

[eluser]obay[/eluser]
thanks!

by the way, i meant this:

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

[eluser]obay[/eluser]
my jquery doesn't seem to get loaded..

this is my directory structure


Code:
+ views
  - page_view.php
  + include
    - jquery.js

in my "page_view.php", i have

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

but it doesn't work. any ideas?
#5

[eluser]rt30000[/eluser]
I typically put my assets (imgs, js, css) in the root directory so as not to get blocked by .htaccess or the CI system. I just find it easier to reference them with a root-relative path. Such as...
Code:
<script type="text/javascript" src="/_assets/js/jquery.js"></script>

[quote author="obay" date="1252957992"]my jquery doesn't seem to get loaded..

this is my directory structure


Code:
+ views
  - page_view.php
  + include
    - jquery.js

in my "page_view.php", i have

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

but it doesn't work. any ideas?[/quote]
#6

[eluser]bretticus[/eluser]
[quote author="obay" date="1252957992"]my jquery doesn't seem to get loaded..

this is my directory structure


Code:
+ views
  - page_view.php
  + include
    - jquery.js

in my "page_view.php", i have

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

but it doesn't work. any ideas?[/quote]

Yes, your paths should always be relative to the main index.php page (as that is the only page that ever gets called directly.)

As mentioned, your "asset" files (or however you want to call them) should not be located in your application folder.

EDIT (my explanation was flawed)
For example, your path says to look in the same directory as your controller/method for a folder called include and then in that jquery.js. Since there is no folders path controller/method (I don't know your URL paths so I substituted controller/method) the broswer cannot find your jquery.js file.

Don't confuse relative paths on the server for relative paths on the browser (or server-side relative paths can be different from client-side relative paths.)
#7

[eluser]Phil Sturgeon[/eluser]
Take a look at my asset library in my signature. It takes care of the structure for you and gives you a very simple syntax to use throughout your application via the helper functions.
#8

[eluser]bretticus[/eluser]
[quote author="Phil Sturgeon" date="1252963830"]Take a look at my asset library in my signature. It takes care of the structure for you and gives you a very simple syntax to use throughout your application via the helper functions.[/quote]

Good stuff Phil! They should incorporate this into CI as this path issue is often confusing for persons using MVC for the first time. Bravo!
#9

[eluser]NateL[/eluser]
I usually put these 3 directories in the same directory as the System folder (I also move the application folder into the same folder as the system folder...up one directory), so my structure looks like this:

|_system
|_application
|_css
|_js
|_images

When you write a view, you will write something similar to this code:

Code:
<link rel="stylesheet" href="<?php echo site_url(); ?>css/styles.css "type="text/css" media="screen" />

You also have to make sure you have your rewrite rules set, if you are messing with a .htaccess file.

I am going to take a look at Phil's asset library system right now. You should too Smile
#10

[eluser]Aken[/eluser]
When using site_url(), it makes a little more sense to me to include the rest of the URL inside the function.

Code:
<link rel="stylesheet" type="text/css" href="<?php echo site_url('css/styles.css'); ?>" />




Theme © iAndrew 2016 - Forum software by © MyBB