Redirecting users to language..

Permalink
I now put this in index.php..

<?php
session_start();
function getLanguage()
{
    $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $lang = substr($lang, 0, 2);
    return $lang;
}
if(!isset($_SESSION['site_language'])){
    $_SESSION['site_language'] = getLanguage();
    switch ($_SESSION['site_language']) {
        case 'en':
            header("Location: /en/");
            break;
        case 'th':


Only I think it is the wrong place.. how to check if a users not access the index? but wants to access a specific page from somewhere then they should not be redirected.

like if somebody wants to see /en/contact/ they should not be redirected... only if they want to access domain/index.php

 
mech7 replied on at Permalink Reply
Ok nevermind this works ok..

In the template:
/*
 * Redirect user to proper language
 */
function getLanguage()
{
    $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $lang = substr($lang, 0, 2);
    return $lang;
}
if($this->c->getCollectionPath() === NULL){
    switch (getLanguage) {
        case 'en':
            header("Location: ".$this->url()."en/");
            break;
        case 'th':


Still wondering if there is anyway to extend the front controller as this should not really be in the theme :P
Mnkras replied on at Permalink Reply
Mnkras
if you look in the index.php it points to the dispatcher.php
mech7 replied on at Permalink Reply
Yes but modifying the dispatcher does not seems like a good idea.. Most frameworks have the ability to extend or override the front controller... or have some sort of bootstrap.
postpostmodern replied on at Permalink Reply
postpostmodern
I agree. I've been trying to figure out how to extend the base/front controller for a while. This article (http://www.concrete5.org/index.php?cID=30241) mentions an 'on_start' hook that will apparently be available in future versions. Check it out for how to implement it now.