本文整理汇总了PHP中Role::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::model方法的具体用法?PHP Role::model怎么用?PHP Role::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionListajax
public function actionListajax()
{
//echo "<pre>";var_dump($_REQUEST);exit;
$pageStart = isset($_REQUEST["iDisplayStart"]) ? intval($_REQUEST["iDisplayStart"]) : 0;
$pageLen = isset($_REQUEST["iDisplayLength"]) ? intval($_REQUEST["iDisplayLength"]) : 10;
$orderCol = isset($_REQUEST["iSortCol_0"]) ? intval($_REQUEST["iSortCol_0"]) : 0;
$orderDir = isset($_REQUEST["sSortDir_0"]) && in_array($_REQUEST["sSortDir_0"], array("asc", "desc")) ? $_REQUEST["sSortDir_0"] : "asc";
$searchContent = isset($_REQUEST["sSearch"]) ? $_REQUEST["sSearch"] : "";
// column name
$colNames = User::model()->attributeNames();
$totalNum = User::model()->count();
$numAfterFilter = User::model()->count();
$criteria = new CDbCriteria();
$criteria->select = '*';
// 只选择 'title' 列
if (!empty($searchContent)) {
$criteria->condition = "uname like '%{$searchContent}%' or email like '%{$searchContent}%'";
}
$criteria->limit = $pageLen;
$criteria->offset = $pageStart;
$criteria->order = $colNames[$orderCol] . " " . $orderDir;
$actionInfos = User::model()->findAll($criteria);
//var_dump($actionInfos);exit;
$entitys = array();
foreach ($actionInfos as $v) {
$t = Role::model()->find("rid={$v['rid']}");
$data = array(0 => $v['uid'], 1 => $v['uname'], 2 => $v['email'], 3 => $t['rname'], 4 => '<a class="btn btn-sm red" href="/main/user/edit?id=' . $v["uid"] . '"><i class="fa fa-edit"></i></a> ' . '<a class="delete btn btn-sm red" data-id="' . $v["uid"] . '"><i class="fa fa-times"></i></a>');
$entitys[] = $data;
}
$retData = array("sEcho" => intval($_REQUEST['sEcho']), "iTotalRecords" => $totalNum, "iTotalDisplayRecords" => $numAfterFilter, "aaData" => $entitys);
echo json_encode($retData);
}
示例2: getRoles
public function getRoles($originalSorting = false)
{
$uid = $this->id;
if (!$uid) {
return [$this->role];
}
## get roles
$roles = Role::model()->with('userRoles')->findAll(ActiveRecord::formatCriteria(['condition' => '|user_id| = :p', 'order' => '|is_default_role|', 'params' => [':p' => $uid]]));
$roles = ActiveRecord::toArray($roles);
if (empty($roles)) {
return false;
}
$idx = 0;
foreach ($roles as $k => $role) {
## find current role index
if ($role['role_name'] == Yii::app()->user->getState('role') && $idx == 0) {
$idx = $k;
}
}
if ($originalSorting) {
return $roles;
}
$role = array_splice($roles, $idx, 1);
array_unshift($roles, $role[0]);
$this->roles = $roles;
return $roles;
}
示例3: run
public function run()
{
$model = new UserForm();
if (($post = $this->request->getPost('UserForm', false)) !== false) {
$model->attributes = $post;
if ($model->save()) {
$this->response(200, '更新用户成功');
} else {
$this->response(500, '更新用户失败');
}
$this->app->end();
} else {
if (($id = $this->request->getQuery('id', 0)) != false) {
if (($user = User::model()->findByPk($id)) != false) {
$model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => $user->state];
$auth = $this->app->getAuthManager();
$roles = $auth->getRoleByUserId($id);
$role = [];
foreach ($roles as $item) {
$role[] = $item->getId();
}
$groups = $auth->getGroupByUserId($id);
$group = [];
foreach ($groups as $item) {
$group[] = $item->getId();
}
$this->render('edit', ['model' => $model, 'role' => $role, 'group' => $group, 'roleList' => Role::model()->findAll(), 'groupList' => Group::model()->findAll()]);
$this->app->end();
}
}
}
$this->response(404, '参数错误');
}
示例4: init
public function init()
{
parent::init();
$cs = Yii::app()->clientScript;
$pt = Yii::app()->homeUrl;
$cs->registerScriptFile($pt . 'js/tinymce/tinymce.min.js', CClientScript::POS_END);
$this->role = Role::model()->findByPk(Yii::app()->user->role);
}
示例5: getRoles
public function getRoles()
{
$roles = array('all' => 'All', 'guest' => 'Guest', 'loggedIn' => 'Logged In', 'super' => 'Super');
if (Yii::app()->hasModule('role')) {
return array_merge($roles, CHtml::listData(Role::model()->findAll(), 'name', 'name'));
}
return $roles;
}
示例6: actionView
public function actionView($menu_id)
{
$model = MenuSection::model();
$links = $model->findAllByAttributes(['menu_id' => $menu_id]);
$roles = Role::model()->findAll();
foreach ($roles as $ind => $role) {
$roles[$role->name] = $role->description;
}
$this->render('view', ['links' => $links, 'roles' => $roles, 'meta' => $model->meta()]);
}
示例7: actionDel
public function actionDel()
{
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : '';
if ($id != '') {
$ret = Role::model()->deleteByPk($id);
RoleAction::model()->deleteAll('rid=:rid', array(':rid' => $id));
var_dump($ret);
} else {
echo "fail";
}
}
示例8: loadModel
public function loadModel()
{
if ($this->_model === null) {
if (isset($_GET['id'])) {
$this->_model = Role::model()->findbyPk($_GET['id']);
}
if ($this->_model === null) {
throw new CHttpException(404, Yii::t('App', 'The requested page does not exist.'));
}
}
return $this->_model;
}
示例9: initRoles
public static function initRoles()
{
$roleArray = array('superman', 'teacher', 'student');
foreach ($roleArray as $value) {
$roleInfo = Role::model()->find("rname=:rname", array(":rname" => $value));
if (!empty($roleInfo)) {
continue;
} else {
$role = new Role();
$role->rname = $value;
$role->save();
}
}
}
示例10: is
public static function is($role)
{
$userId = Yii::app()->user->id;
if (!$userId) {
return false;
}
$isRole = in_array($role, User::model()->findByPk($userId)->roles);
$roleObj = Role::model()->findByAttributes(array('name' => $role));
if (!$roleObj) {
// throw new CHttpException(500, 'No role named ' . $role . ' exists!');
return false;
}
$isActive = $roleObj->active;
return $isRole && $isActive;
}
示例11: actionLoadParties
public function actionLoadParties()
{
$data = "<option value=''></option>";
$accounttype = isset($_POST['accounttype'])?$_POST['accounttype']:null;
if(empty($accounttype))
{
$this->returnJsonResponseII($data);
}
$tmparray = array();
if($accounttype === Helper::CONST_Receivables)
{
$rolename = Helper::CONST_Customer;
}
else
{
$rolename = Helper::CONST_Contractor;
}
$role = Role::model()->getRoleByName($rolename);
if(empty($role))
{
$this->returnJsonResponseII($data);
}
$role_id = $role->id;
$criteria = new CDbCriteria;
$criteria = Yii::app()->controller->getPeopleCriteria($role_id, false);
$tmparray = Person::model()->findAll($criteria);
//$data = CHtml::listData($tmparray, 'id', 'name');
$i = 0;
foreach($tmparray as $single)
{
$tmp = "<option ";
if($i === 0)
{
$tmp .= " selected = 'selected'";
}
$i++;
$tmp .= " value='" . $single->id ."'>" . $single->name . "</option>";
$data .= $tmp;
}
$this->returnJsonResponseII($data);
}
示例12: save
public function save()
{
try {
if ($this->id) {
$model = Role::model()->findByPk($this->id);
if (empty($model)) {
throw new CDbException('参数出错', 1, []);
}
} else {
$model = new Role();
}
$model->attributes = ['name' => $this->name, 'description' => $this->description, 'status' => $this->status];
if ($model->save() === false) {
throw new CDbException('更新用户出错', 2, $model->getErrors());
}
} catch (CDbException $e) {
$this->addErrors($e->errorInfo);
return false;
}
return true;
}
示例13: getFewRecordsTitle
public function getFewRecordsTitle($attrName, $attrValue)
{
if ($attrName == 'roles') {
$builtInRoles = Role::builtInRoles();
if (isset($builtInRoles[$attrValue])) {
return $builtInRoles[$attrValue];
} else {
$role = Role::model()->findByAttributes(array('name' => $attrValue));
if ($role) {
return $role->title;
} else {
return parent::getFewRecordsTitle($attrName, $attrValue);
}
}
} elseif ($attrName == 'login') {
$user = User::getByLogin($attrValue);
if ($user) {
return $user->getFullname();
} else {
return parent::getFewRecordsTitle($attrName, $attrValue);
}
} else {
return parent::getFewRecordsTitle($attrName, $attrValue);
}
}
示例14: createRoleOrigin
/**
* Create Role root - Original Role for System
*
* Role name: root
* Create automatic: Yes
*/
public function createRoleOrigin()
{
$root = Role::model()->findByPk(1);
if (empty($root)) {
$listRole = $this->_originRole();
$data = array();
try {
foreach ($listRole as $value) {
$role = new Role('setup');
$role->setAttributes($value);
$role->save();
}
$this->redirect($this->addRootOrigin());
} catch (Exception $ex) {
$data['roles'] = array_keys($listRole);
$data['errmsg'] = $ex->getMessage();
}
$this->render('role', $data);
} else {
$this->redirect($this->addRootOrigin());
}
}
示例15:
* @link http://yupe.ru
**/
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', ['action' => Yii::app()->createUrl($this->route), 'method' => 'get', 'type' => 'vertical', 'htmlOptions' => ['class' => 'well']]);
?>
<fieldset>
<div class="row">
<div class="col-sm-3">
<?php
echo $form->textFieldGroup($model, 'id', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('id'), 'data-content' => $model->getAttributeDescription('id')]]]);
?>
</div>
<div class="col-sm-3">
<?php
echo $form->dropDownListGroup($model, 'user_id', ['widgetOptions' => ['data' => CHtml::listData(User::model()->findAll(), 'id', 'first_name')]]);
?>
</div>
<div class="col-sm-3">
<?php
echo $form->dropDownListGroup($model, 'role_id', ['widgetOptions' => ['data' => CHtml::listData(Role::model()->findAll(), 'id', 'name')]]);
?>
</div>
</div>
</fieldset>
<?php
$this->widget('bootstrap.widgets.TbButton', ['context' => 'primary', 'encodeLabel' => false, 'buttonType' => 'submit', 'label' => '<i class="fa fa-search"> </i> ' . Yii::t('UserModule.user', 'Искать Должность')]);
?>
<?php
$this->endWidget();