Welcome Guest, Not a member yet? Register   Sign In
Question about best practices for write anchors
#1

[eluser]JulianM[/eluser]
Hi,

I would like to know your opinion about what are the best practices to write anchors in an application that uses custom routes.

Mostly of my applications are multi-language. For example, imagine a simple master/detail application. You need to link from a List to each detail view with id=27.

English: /product/27
Spanish: /producto/27

So, I have a route from /producto (in Spanish) to /product controller in English.

But at the time I write anchors in the master view to link to each detail view, I would like to use the right language.

For example:
<?php echo anchor('product/27') ?> when I am in English language
<?php echo anchor('producto/27') ?> when I am in Spanish language

What do you think is the best approach to specify the anchors?
Should I use a helper that render the right route each time?

Thanks.

Julian
#2

[eluser]TheFuzzy0ne[/eluser]
It depends how complex your application is. Would a route not suffice?
Code:
$route['producto/(.+)'] = 'products/$1';
#3

[eluser]JulianM[/eluser]
Hi TheFuzzyOne. Well, in the past I simple used links to the main controller when I needed along the application, independently about the routes I have used.

I understand your route rule, but inside the application I would use links accordingly to the selected language, because I think that improves the site readability and navigability as well as SEO.

For example, if I am an English user, I would read the links as /product/id but if I am a Spanish guy I would like to read the links as /producto/id

So, given this, I would need to write different URL among the application, for example using anchor().

I would like to know if other developers do not mind about this issue or if there is any good practice to write these links.

Thanks




[quote author="TheFuzzy0ne" date="1236989885"]It depends how complex your application is. Would a route not suffice?
Code:
$route['producto/(.+)'] = 'products/$1';
[/quote]
#4

[eluser]TheFuzzy0ne[/eluser]
How does CodeIgniter know whether a user is using the English or Spanish version of the site?

I think you're going to have to use the Language class.




Theme © iAndrew 2016 - Forum software by © MyBB