As promised, here is my solution.
fresh from the kitchen, so it needs some cooling down.
but it's eatable i think (at least it tastes good to me!)

in routes.php add this _BEFORE_ your routes

        include_once("translate.php");
        $from_url = translate($from_url);

then create translate.php in the same folder as routes.php and put this
in it:
(make sure there are no newlines or whitespace outside the php tags!)

<?php
        function translate($var = null,$level="total")
        {
                if($var)
                {
                        if($level=="total")
                        {
                                $old = explode('/',$var);
                                $lastone = end($old);
                                if(empty($lastone)) array_pop($old);
                                $new = array();

                                /* translate each part where you have a mapping 
table for */
                                if(sizeof($old))        $new[0] = 
translate($old[0],"controller");
                                if(sizeof($old)>1)$new[1] = 
translate($old[1],"action");

                                /* copy remaining entries, if any.  
array_merge() is not suitable
for this :( */
                                for ($i = 2; $i < sizeof($old); $i++)
                                {
                                        $new[$i] = $old[$i];
                                }

                                /* construct the translated url.  this also 
adds a trailing "/"
even if it wasn't in the original */
                                $new_url="";
                                foreach($new as $n)
                                {
                                        $new_url .= $n."/";
                                }
                                return $new_url;
                        }
                        else
                        {
                                $table = array('controller'     => 
array('nieuws' => 'news',
                                                                                
                                                        'aanbiedingen' => 
'offers'
                                                                                
                                                ),
                                                                        
'action'                => array('bekijk' => 'view',
                                                                                
                                                        'verwijder' => 'delete',
                                                                                
                                                        'voegtoe' => 'add'
                                                                                
                                                )

                                                                        );
                                if(isset($table[$level]))
                                {
                                        foreach ($table[$level] as $orig => 
$new)
                                        {
                                                if($var == $orig) $var = $new;
                                        }
                                }
                                else
                                {
                                        if(DEBUG) echo("translate table for 
level ".$level." not found:
".$var." left untranslated\n");
                                }
                                return $var;
                        }
                }
        }
?>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to