How to create Sub Domains using Cake PHP?

Answer

With the wildcard DNS record in place, you can then use HTTP_HOST, or the CakePHP way, $request->host() to determine the hostname (subdomain) being used to access your system. You can then load the correct profile details in the beforeFilter() method of AppController and move forward from there.

 

class User extends AppModel
{
     public $belongsTo = array(
          'Profile'
     );

     public function findByProfileHostname($hostname) {
         return $this->find('first', array('conditions' => array(
             'Profile.hostname' => $hostname
         ));
     }
};

class AppController extends Controller
{
    public function beforeFilter () {
        $this->ActiveUser = $this->User->findByProfileHostname($this->request->host());
        if (!$this->ActiveUser) {
            throw new InvalidArgumentsException(__('%s is not active here', $this->request->host()));
        }
    }
}

All dns Questions

Ask your interview questions on dns

Write Your comment or Questions if you want the answers on dns from dns Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---