Welcome Guest, Not a member yet? Register   Sign In
Newbie: current_url() inside anchor()
#1

[eluser]MEM[/eluser]
Hello all,

It's weird that I cannot find anyone who actually have asked this on the forums, so I'm wondering if I'm doing something structurally wrong... Probably.

I'd like to configure some navigation menu links and, let's assume, I cannot change the third segment of the URI, so I need to add a new segment on the URI.

Let's say we have something like this:
http://www.site.com/c_categoria/seccao/1

And once we click on a menu link, we want to get something like this instead:
http://www.site.com/c_categoria/seccao/1/22


1)
What is the right syntax in order to use current_url() inside the anchor()?

Regards,
Márcio
#2

[eluser]MEM[/eluser]
Answer:

Something like this will do it:
echo anchor(current_url().'/'.$subcategorias['id_cat'].'/',$subcategorias['nome_cat']);


Regards,
Márcio
#3

[eluser]Jônatan fróes[/eluser]
Hi, Marcio.
Are you from Brazil? You should join in our
email list
----
Code:
<?php
//uri_segments() returns 'c_categoria/seccao/1'
echo anchor( uri_segments() . '/22', 'clique aqui')
?>
#4

[eluser]MEM[/eluser]
Thanks. Jônatan. I'm on your list. And I'm also writing some tutorials our your codegigniter.com.br site Wink

I just post a related question on the email list.

Thanks for your tip. The problem with current_url() is that it will always increment a /something when you click on the link, because he will always get the current_url(). Maybe your snipped code helps me solving that... I will test.

Regards,
Márcio
#5

[eluser]MEM[/eluser]
Nop. Sad No luck.

Actually, if I use:
uri_segments()

I get:
Fatal error: Call to undefined function uri_segments()

I've used:
uri_string()

instead.

However, the issue remains:
If we repetitively click on our menu, we still get a wider and wider url path. Sad
#6

[eluser]Jônatan fróes[/eluser]
[quote author="MEM" date="1255800866"]Thanks. Jônatan. I'm on your list. And I'm also writing some tutorials our your codegigniter.com.br site Wink

I just post a related question on the email list.

Thanks for your tip. The problem with current_url() is that it will always increment a /something when you click on the link, because he will always get the current_url(). Maybe your snipped code helps me solving that... I will test.

Regards,
Márcio[/quote]

You're right, Marcio. It will always increment something...
#7

[eluser]Jônatan fróes[/eluser]
[quote author="MEM" date="1255801406"]Nop. Sad No luck.

Actually, if I use:
uri_segments()

I get:
Fatal error: Call to undefined function uri_segments()

I've used:
uri_string()

instead.

However, the issue remains:
If we repetitively click on our menu, we still get a wider and wider url path. Sad[/quote]


Did you load the url helper?

Maybe if you create a variable in your controller and use it in your view you can solve the problem:

something like this:
Code:
<?php
//controller
$default_url = 'xx/yy/';

//view
echo anchor ($default_url . 'zz', 'clique aqui');
?>

What you think?
#8

[eluser]MEM[/eluser]
[quote author="Jônatan fróes" date="1255809574"]
Did you load the url helper?
[/quote]

yes. With this line on autoload.php :
$autoload['helper'] = array('url','form','text','date','security');


[quote author="Jônatan fróes" date="1255809574"]
Maybe if you create a variable in your controller and use it in your view you can solve the problem:

something like this:
Code:
<?php
//controller
$default_url = 'xx/yy/';

//view
echo anchor ($default_url . 'zz', 'clique aqui');
?>

What you think?
[/quote]

I see.. but the issue is that the $default_url needs to change as well, depending on the user actions made on another menu.

This may sound weird, but please have a look on the following link, in order to see the context of this post:
http://ellislab.com/forums/viewthread/132374/

I need all the help I can get, if you can... please advice on the link above, I would be more then happy because I'm stuck on this for months now. Confused


Abraço,
Márcio




Theme © iAndrew 2016 - Forum software by © MyBB