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()));
}
}
}