Hi guys,
EDIT:
Sorted the first question!
First question:
I was creating an imaginary customer login section on my site, and wanted to show them a login form if they didn't have cookies set for username and password, or show them their personal page if they'd logged in & had the credentials stored correctly. Just as a learning task.
The problem I had was, while I knew how to render a page different from the one I was currently in the controller for (in this case, if they were logged in), but I didn't know how to render the original page manually (my 'if' statement needed an 'else'). Here was the solution:
if (($email = $cookie->get('ClientEmail')) && ($pass = $cookie->get('ClientPassword')))
{
$where = "Client.ClientEmail = '" . $email . "'";
$where .= " AND Client.ClientPassword = '" . $pass . "'";
if($client = DataObject::get_one("Client", $where, "", "", ""))
{
return $this->customise(array('Client' => $client))->renderWith(array('ClientPage', 'Page'));
}
else
{
$cookie = new Cookie;
$cookie->forceExpiry('ClientEmail');
$cookie->forceExpiry('ClientPassword');
$this->setMessage('bad', 'Invalid session');
Controller::redirectBack();
}
}
else
{
// This is the code I was originally asking for, ClientHolder is the template & controller I am currently working in
$page = Director::get_current_page();
return $this->renderWith(array('ClientHolder', 'Page'));
}
Bonus question:
In this 'if' statement
if (($email = $cookie->get('ClientEmail')) && ($pass = $cookie->get('ClientPassword')))
I had to evaluate both conditions separately, whereas normally I would remove the extra brackets like this
if ($email = $cookie->get('ClientEmail') && $pass = $cookie->get('ClientPassword'))
However, with the brackets removed, $email always returned '1'. Any idea why this would be? Thanks