CodeIgniter Forums

Full Version: [OT] Nav breaks with method call in URL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

CI version 3.1.0

I marked as OT because I'm not sure if CI is the problem here.

I'm working on my first CI site (and have wanted to try out CI for years!):
dev.sunshineartist.com

If you notice, there are two drop down menus in the main nav, 'subscribers' and 'events'.

The issue is that those two nav menu's work fine when there is no method called in the URL (hovering enacts the dropdown), but they don't work when there is.... so, for example:
http://dev.sunshineartist.com/aboutus
http://dev.sunshineartist.com/subscribers

Both work. But:
http://dev.sunshineartist.com/subscribers/promoters
http://dev.sunshineartist.com/events/eventlisting

disables the drop down. Nothing is reported in the console, and this is a nav that I did not build from scratch.. so I'm out of ideas at the moment.

Any thoughts appreciated.

TIA,
Donovan
It sounds like your js file is not being found because your js is not working. This is nothing to do with CI.

Taking a quick peek at your code:

Code:
<script src='js/device.min.js'></script>

Once a method is used, this link becomes something like:

Code:
http://dev.sunshineartist.com/events/js/device.min.js

Rather than as you intended:
http://dev.sunshineartist.com/js/device.min.js

You should use:
Code:
<script src='/js/device.min.js'></script>
notice the first forward slash making the link use the base domain root, or even better:
PHP Code:
<script src='<?php echo base_url('js/device.min.js'); ?>'></script

This was the first one I found, but you may have others on the page.

Hope that helps,

Paul

Base URL in the docs: http://www.codeigniter.com/user_guide/he...l#base_url
Thanks Paul.. your post just made me dig deeper in the javascript (issue was a nested document.write for a .js file ).

And thanks for pointing out the single .js call that I missed with base_url!  by the way, I have been calling base URL such as:
Code:
<img src="<?php echo base_url(); ?>images/SA-Logo-Web-507.png" />

Which is a bit different than what you posted... is there a benefit one way or another?

Thx!
Donovan
Not really, base_url() will output the base url, base_url('foo/bar') will output the base url with foo/bar on the end.

Docs: http://www.codeigniter.com/user_guide/he...l#base_url

Personally I prefer to use it with the link inside the function call. I think it is cleaner myself:
PHP Code:
<img src="<?php echo base_url(); ?>images/SA-Logo-Web-507.png" />

<
img src="<?php echo base_url('images/SA-Logo-Web-507.png'); ?>" /> 

But either is fine.

Paul.