I am trying to get a multilingual site up according to this tutorial:
http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
Things look good in terms that clicking on a switch-language link works. However, when you first come to the site, i would like it to go to the default language example.com/eng/ instaed of just being example.com/.
Basically, for SEO purposes, I don't want my site to have non-lingual content, should always have the language in the url.
How could I do that and also go through the function that saves the language in session/cookie?
thanx
Looking at the article, all you should need is a simple check for the 'language' param in the URL:
function beforeFilter() {
// check and perform a redirect
if (empty($this->params['language'])) {
$this->redirect(array('language' => 'eng'));
}
// the following method sets any cookies
$this->_setLanguage();
}
Related
Is it possible to override the standard 'Create new ' button and 'detail' link in the list view of service cloud console?
I want to show my custom VF pages on click of these buttons/links.(if yes how?)
In addition, any examples to the service cloud API toolkit would be helpful.
Thanks in advance.
Best would be to create separate set of buttons as it's less redirects...
If you want to really override standard ones I think you'll have to use normal overrides (on all buttons) but with content based on Javascript you'd be deciding what should happen.
http://www.salesforce.com/us/developer/docs/api_console/index.htm - Console JS API will be handy.
Make a visualforce page that uses standardController="Your_Object__c". In the content include a reference to the Console API and code similar to this example of isInConsole():
<apex:includeScript value="/support/console/27.0/integration.js"/>
<script type="text/javascript">
function testIsInConsole() {
if (sforce.console.isInConsole()) {
alert("in console");
} else {
alert("not in console");
}
}
</script>
Except you'll be redirecting either to your special pages or to standard "new" and "edit". To force going to original edit mode you can add nooverride=1 parameter in the URL (which is also mentioned in the documentation of URLFOR function).
Normal "new Account" (results in override if specified): /001/e
Force go to your page: /apex/NewAccount
Force go to standard page: /001/e?nooverride=1
So now you have an idea how to detect whether you're in console or not and where to go. Only remaining question is "which window should redirect". Because Console is built on frames you might get different results on using javascript window, location, parent etc. objects. That's a general knowledge how to work with frames in JS so I'm not going to write that up. But I'll include a link to srcUp() function provided by salesforce that you might want to reuse.
I think it's defined only in Console context to be honest so maybe you could ditch the whole isInConsole in favor of typeof srcUp != 'undefined'?
Good luck :)
I'm having troubles with the CakePHP's (2.3) CacheHelper.
This is realy a powerful tool, but it's not so suitable for what I'm doing.
I have a internationalised website and the language is set either by the user's preferences or by "forcing" it with an URL argument (lang:xx).
So, the cached page "controller/action/yy" can be the same page as "controller/action/yy/lang:xx". And worst, "controller/action/yy" can be cached in english, french or whatever.
Is there a way to change the name (the prefix is clearly not a solution here) of the cached file (so that "controller/action/yy" will always be cached as "controller/action/yy/lang:xx" by adding the user's preferences language) ?
Thanks in advance !
Sébastien
You can in your beforeRender change the prefix of the file:
Configure::write('Cache.viewPrefix', 'YOURPREFIX');
And you can get your prefix from params or session (depends of your app).
I didn't get why prefix is not useful. You will have one file for each language for each page. Something like "eng_my_action" file.
If you want to save only 1 file and translate it with the user language makes non sense. Because view already do that (only a parser of the data).
Fonts:
http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html#using-the-helper (looking for new in version 2.3)
Well,
I will sample the awnser to you understand:
public function beforeRender(){
$lang = isset($this->params["named"]["lang"]) ? $this->params["named"]["lang"] : "eng"; // verify if is the default language(eng) or is in params
if($this->Auth->user("lang")){
$lang = $this->Auth->user("lang"); // This is a example how to take the default language from a user. You need to change it to your app.
}
Configure::write('Cache.viewPrefix', $lang);
}
What is the best approach for implementing multilanugage site in CakePHP:
1) http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
2) http://cakedc.com/pierre_martin/2010/08/05/i18n-routes-with-cakephp-1-3
3) Or something else?
Thanks!
3) For a website that i worked on, i was asked to translate the url and the pages but REALLY translate the url, for example the urls should be:
[EN]
www.mysite.com/products
[ES]
es.mysite.com/productos
[FR]
fr.mysite.com/produits
I guess this improves SEO when someone makes a search in a specific language.
To achieve this, I stored the language in the session and i my routes were something like:
Router::connect(__('/products',true), array('controller' => 'products', 'action' => 'index'));
(Hmm now that i think about it... i dont even need to store the lang in Session because i know the language to display by reading the subdomain.)
And if you want to, you can store a cookie to save the preferred language for the user. To change the language, you only need to redirect the user to the corresponding subdomain. (but it will be tricky,but not impossible, if you want to redirect him to the same page he was in but in a different language)
Seems to me that this was a really simple way to translate urls.
Hope this helps
How do I do a simple route in CakePHP?
I need that each and every URL will be routed by swapping the action and the controller.
I just couldn't understand the placeholders syntax.
Example:
/files/read/3
to
/read/files/3
-- supplemental --
In my application I use aliases for the controllers.
and I want to route every url that have a certain keyword, as an action, to a certain controller.
I also want to provide the original controller name as a parameter.
Here is a 1:1 example:
There are to alises: fruits and streets.
The keyword that I want to catch in the action is find.
The new controller name is finder.
The following calls match my condition:
/fruits/find/apple/red and /streets/find/longer
The router should catch these urls and convert them, to:
/finder/fruits/apple/red(or supply the parameters in other way, I don't mind) and /finder/streets/longer
How should it be done?
Here is the line of code that you need to put in /app/config/routes.php:
Router::connect('/:action/:controller/*', array('controller' => ':controller', 'action' => ':action'));
Know more: As you can see from the CakePHP book, there are some 'reserved' patterns for routing configuration. An example would be what I used in the line above: :action and :controller. These patterns allow you to tweak routes extensively.
Beware: changing the order of controller and actions in urls might have unintended consequences in the functionality of other CakePHP features. I haven't tested thoroughly, but this is just a general warning.
Beware: Also, I noticed that you put in your example: /files/read/3. Maybe this was just some dummy example, but if you indeed plan to have an MVC named as 'file', be advised that it will conflict will CakePHP core classes (e.g. File model will conflict with File class).
Anyway, hope this answer helps you well. And I really like how the change of controller and action names make the url more readable. :D
I am rewriting our company website in cakephp, and need to find a way to do the following:
A user enters our site by using one
of the promotional alias URLS that
has been pregenerated for a specific
media advert ( magazine, web
promotion etc )
The URL is checked against a
database of alias URLs, and if an
alias exists, then a specific
tracking code is written into the
session.
I have considered several options, none of which seem suitable for this purpose. They are:
Putting the lookup script in the
beforeFilter() in appcontroller, so
that its included in every
controller. (Writes a session value
so it only perfoms once.)
This option only works for existing contollers, and gives the
Cake 'missing controller' error if a
URL doesn't exist.
Specific routes for each alias in
Routes.php - Works but there are
potentially hundreds of alias urls
added/removed regularly via admin
interface.
Route all site URLs to their own
actions, and having an 'everything
else' rule, for the alias URLs that
maps to my lookup script. - Messy
and I lose the built in Cake
routing.
Custom 404. - I don't want to
return 404's for these urls, as I
feel its bad practice unless they
really don't map to anything.
I really could do with a place in the application flow where I can put this lookup/tracking script, and I'm fairly new to cake so I'm stumped.
EDIT: Also, I know that a subfolder called say 'promo' would easily do this, but I have a lot of legacy URLS from our old site, that need handling too.
Note: I'm making an assumption that your promo URLs are in the form of "domain.com/advert-259" or something like that (i.e. no "domain.com/adverts/advert-259'). That would be just too simple :)
Hopefully, you can use the routing with some regex. Add this to your /config/routes.php and let me know if a different regex will help :)
$controllers = Configure::listObjects('controller');
foreach ($controllers as &$value)
{
$value = Inflector::underscore($value);
}
Router::connect('/:promo', array('controller' => 'promos', 'action' => 'process'), array('promo' => '(?!('.implode('|', $controllers).')\W+)[a-zA-Z\-_]+/?$'));
Now you can handle all your promo codes in PromosController::process().
Basically, it checks for a promo code in url, excluding those in the $controllers array (i.e. your regular routes won't be messed up).
Later on you might want to consider caching the value of Configure::listObjects() depending on the speed of your app and your requirements.
A very interesting question. I think I would use item #3. It's not really that messy -- after all, this typically is handled by the pages controller in my stuff. That's how I'd handle it - hardcode your routes to your controllers in routes.php, then have a matchall route that will work for your promo codes. This allows you to keep legacy URLs, as well as use a lot of the standard cake stuff (you probably will just have to explicitly state each of your controllers routes, not such a chore...) Additionally, it will let you do some cool stuff with 404 errors -- you can put some logic in there to try and figure out where they were trying to go, so you can superpower your 404's.