Hello,

You could do something like this to start:

        protected function _getSubDomain() {
                $url = explode('.', $_SERVER['HTTP_HOST']);
                return $url[0];
        }

        public function index() {

                $locale = $this->_getSubDomain();

                if($getSubDomain != 'www') {
                        $cityresults = $this->Thread->find('all', array(
                                'recursive' => -1,
                                'conditions' => array(
                                        'city_slug' => $locale
                                ),
                                'limit' => 50
                        ));
                        debug($cityresults);
                } else {
                        //site at www.
                }
        }

Andras Kende
http://www.kende.com


On Nov 24, 2012, at 2:45 PM, treckstar <trecks...@gmail.com> wrote:

> Hi everyone.  I am working on a little project to learn more about Cake that 
> involves using a "locale" as a sub domain.  An example of a popular website 
> that incorporates this type of functionality is craigslist. ex: 
> pittsburgh.craigslist.org
> 
> I am running the latest version of Cake, 2.2.3 on a Lamp stack.  My Vhost and 
> DNS are configured for wildcard sub domains.  I only want to use 1 App to 
> handle all my subdomains.
> 
> To sum up why I am posting, I am confused on what the best way to setup my 
> application to handle a sub domain as a parameter in my actions.
> 
> Lets say I have 3 baked Models: Locale, Category, and Thread.  Locale and 
> Category have many Threads.
> 
> When I am in the "view" of a single Thread, I want the sub domain to act as a 
> parameter for the view action, so that I don't have to clutter the rest of my 
> URL with arguments.  Essentially, I would want my URL to look something like 
> this.  http://:locale.example.com/:category/:thread_id
> 
> I also had the idea of storing the Locale parameter as a session variable, 
> but I am not sure if this is the best way to do it.
> 
> I know I need to use the router somehow to achieve this URL pattern, but I am 
> not sure the best way to accomplish this.
> 
> Does anyone have any suggestions on the most efficient way to accomplish this?
> 
> Thanks!  Cake is great, let me know if you are confused on my goal.  I will 
> elaborate more.
> -treckstar
> 
> 
> 
> -- 
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> --- 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to 
> cake-php+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>  
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to