• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Link problem

#1
[eluser]Gerep[/eluser]
Hi fellas,

I'm new here and trying to develop a quotation system but I'm having a little problem.

I have the menu with links like:
Quote:<ul>
<li><a href="user">Index</a></li>
<li><a href="quotation">Quotation</a></li>
</ul>

If I got it right, the first link will call my user class and execute the index() method. When I click on it for the first time it adds the user to the url like:
Quote:http://localhost/quotation/user
, when I click the second time, it will be:
Quote:http://localhost/quotation/user/user
and it makes all my other links wrong, like the Quotation:
Quote:http://localhost/quotation/user/user/quotation

Am I doing the right thing with links or there is another and better way to deal with them?

Thanks in advance

#2
[eluser]spider pig[/eluser]
If I understand what you want to do, you will need to prefix the links with base_url(). This will then insert the correct web address when executed. So the menu would look like this:

Code:
<ul>
<li><a href="&lt;?= base_url() ?&gt;user">Index</a></li>
<li><a href="&lt;?= base_url() ?&gt;quotation">Quotation</a></li>
</ul>

To use base_url(), you will need to make sure the URL Helper is loaded in the controller:

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

Or, what I do is load it in the config file autoload.php:

Code:
$autoload['helper'] = array('url');

#3
[eluser]parham90[/eluser]
[quote author="spider pig" date="1280910540"]If I understand what you want to do, you will need to prefix the links with base_url(). This will then insert the correct web address when executed. So the menu would look like this:

Code:
<ul>
<li><a href="&lt;?= base_url() ?&gt;user">Index</a></li>
<li><a href="&lt;?= base_url() ?&gt;quotation">Quotation</a></li>
</ul>

To use base_url(), you will need to make sure the URL Helper is loaded in the controller:

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

Or, what I do is load it in the config file autoload.php:

Code:
$autoload['helper'] = array('url');
[/quote]

Or even better, after autoloading (or loading) the url helper, you can put these in your view file, which is, in my opinion, much more readable:

Code:
<ul>
<li>&lt;?php echo anchor('user', 'Index');?&gt;</li>
<li>&lt;?php echo anchor('quotation', 'Quotations');?&gt;</li>
</ul>

If you have short tags enabled in your CodeIgniter configuration file, you can even make it as short as:

Code:
<li>&lt;?=anchor('user', 'Index')?&gt;</li>

and so on.

For more information about the URL helper and more examples, take a look at the section about the URL helper in the User Guide.

HTH!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.