本文整理匯總了PHP中models\User::setRoles方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::setRoles方法的具體用法?PHP User::setRoles怎麽用?PHP User::setRoles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models\User
的用法示例。
在下文中一共展示了User::setRoles方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: connect
public function connect(Application $app)
{
// creates a new controller based on the default route
$front = $app['controllers_factory'];
$front->get("/", 'FrontController\\Homepage::index')->bind("homepage");
$front->match("/final_test", 'FrontController\\FinalTest::index')->bind("final_test");
$front->match("/control_test", 'FrontController\\ControlTest::index')->bind("control_test");
$front->match("/{course_type}", 'FrontController\\CourseType::index')->bind("course_type");
//$front->post("/{course_type}", 'FrontController\Score::index')->bind("course_type");
$app->get('/logout', function (Request $request) use($app) {
$app['session']->set('username', '');
$app['session']->set('id', '');
$redirect = $app["url_generator"]->generate("homepage");
return $app->redirect($redirect);
})->bind("logout");
$app->post('/login-check', function (Request $request) use($app) {
$em = $app['orm.em'];
$qb = $em->createQueryBuilder();
if (null !== $request->get('username2')) {
$username = $request->get('username2');
$query = $qb->select('u')->from('models\\User', 'u')->where("u.username = '" . $username . "'")->getQuery();
$result = $query->getResult();
$result_count = count($result);
if ($result_count > 0) {
return 'Helaas, de gebruikersnaam die je hebt ingevoerd bestaat al, probeer eens een andere.';
} else {
$user = new User();
$user->setUsername($username);
$user->setRoles("ROLE_USER");
$em->persist($user);
$em->flush();
$id = $user->getId();
$app['session']->set('id', $id);
$app['session']->set('username', $username);
return 'succes';
}
} else {
if ($request->get('username') != '') {
$username = $request->get('username');
$query = $qb->select('u')->from('models\\User', 'u')->where("u.username = '" . $username . "'")->getQuery();
$result = $query->getResult();
$result_count = count($result);
if ($result_count < 1) {
return 'De gebruikersnaam die je hebt ingevoerd bestaat niet, probeer het eens opnieuw.';
} else {
$id = $result[0]->id;
$app['session']->set('id', $id);
$app['session']->set('username', $username);
return 'succes';
}
}
}
})->bind("login_check");
return $front;
}
示例2: setRoles
/**
* {@inheritDoc}
*/
public function setRoles($roles)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setRoles', array($roles));
return parent::setRoles($roles);
}