0

I have a CI folder structure like this:

-> root  
- - >application  
- - >resources  
- - >system

In the resources folder, I have separate folders like 'css', 'images', 'js', 'js/plugins' etc.

I have a twitter plugin in js/plugins folder which needs the base path of the site. I used it like this :

modpath: 'resources/plugins/twitter/',  

And it works if the url that i visited is localhost/myapp/ , but doesn't work when the url is localhost/myapp/index.php/welcome

What i have to do ?

Because it is not a controller or a view, i can't use it as <?=site_url();?> right? So what i need to do?

Thanks for help !

2
  • 1
    This appears to be your 18th question so far. It's time you start taking care of giving proper format to source code (and make, e.g., PHP code actually display). BTW, your question does not seem to have anything to do with Microsoft ECMAScript implementation so I've edited out that referent from title. Commented Jul 12, 2014 at 14:01
  • can you provide any links of that twitter plugin ? Commented Jul 12, 2014 at 21:33

6 Answers 6

1

You should use the full path to your files, in my CI projects I use something like this:

<script src="<?=base_url()?>js/twitter.js

Remember that your assets must be in the /public folder.

Sign up to request clarification or add additional context in comments.

1 Comment

But this is not a view file. This is a js source file. I think base_url() function will not work, since it's not in the application folder.
1
+50

In your view file, before loading any javascripts add something like this

<script>
var base_url = '<?php echo base_url(); ?>';
</script>

This would make a javascript variable called base_url available to all other files you load after the definition.

Now in your javascript file you can do something like:

modpath: base_url + 'resources/plugins/twitter/',

Comments

0

Assume your base_url() is localhost/myapp/

Then use $this->config->base_url() in src like

<script src="<?= $this->config->base_url(); ?>resources/plugins/twitter/twitter.js"></script>

2 Comments

But this is not a view file. This is a js source file. I think base_url() function will not work, since it's not in the application folder.
Then create a <div id="base_url" style="display:none"><?= $this->config->base_url();?></div>, and then get the value of DIV using $("#base_url").text() inside the JS
0

Check this with ur view file

<script src="<?php echo base_url();?>resources/plugins/twitter/twitter.js"></script>

1 Comment

But this mod path: 'resources/plugins/twitter' line is not in a view file. It is in the twitter.js.
0

I usually do this, in my View:

<script src="<?php echo base_url();?>resources/js/yourscript.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>"resources/css/bootstrap.css" />

to load resources (script files, or anything else) that stored locally.

Comments

0

Create js folder on the root where application and system folders are placed then place javascript file on that folder then on the view where you want to use this javascript file write down the following path:-

<script src="<?php echo $this->config->item('base_url') ?>js/fileName.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.