本文整理匯總了PHP中Website::find_by_code方法的典型用法代碼示例。如果您正苦於以下問題:PHP Website::find_by_code方法的具體用法?PHP Website::find_by_code怎麽用?PHP Website::find_by_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Website
的用法示例。
在下文中一共展示了Website::find_by_code方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: gotosite
public function gotosite($site = null)
{
if ($this->GetData('site')) {
$site = $this->GetData('site');
}
$site = Website::find_by_code($site);
if (!$site) {
Site::Flash('error', 'Unable to find the site you want to go to');
Redirect('');
}
if ($user = Site::CurrentUser()) {
try {
$login = new Login();
$login->user_id = $user->id;
$login->user = $user;
$login->website_id = $site->id;
$login->website = $site;
$login->ip = Site::RemoteIP();
if ($login->save()) {
header("Location: {$login->url}");
die;
} else {
Site::Flash('error', 'Unable to redirect you');
Redirect('');
}
} catch (Error500 $e) {
$error = 'Error';
if ($e->getMessage()) {
$error .= ': ' . $e->getMessage();
}
Site::Flash('error', $error);
Redirect('');
}
} else {
if ($site) {
header("Location: {$site->url}");
die;
}
Site::Flash('error', 'Unable to go to site');
Redirect('');
}
}
示例2: xlogin
/**
* Retrieves a one time URL for a login into a website
*
* @arg string The RPCSession code
* @arg int The user ID to login
* @arg string The name of the site
* @arg string The IP of the user
*
* @param object $method The name of the RPC method
* @param object $args An array of arguements, listed above
* @return string The URL to use to access that site
* @throws RPCException
*/
public function xlogin($method, $args)
{
$this->auth($args[0]);
if (count($args) < 4) {
throw new RPCException('Invalid Arguements', 500);
}
$user = User::find_by_id($args[1]);
if (!$user) {
throw new RPCException('Unable to find user', 500);
}
$site = Website::find_by_code($args[2]);
if (!$site) {
throw new RPCException('Unable to find site', 500);
}
$destination = '';
if (isset($args[4])) {
$destination = $args[4];
}
$login = new Login();
$login->user_id = $user->id;
$login->user = $user;
$login->website_id = $site->id;
$login->website = $site;
$login->destination = $destination;
$login->ip = $args[3];
if ($login->save()) {
return $login->url;
} else {
throw new RPCException($login->errorString(), 500);
}
}