本文整理汇总了PHP中Roles::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::insert方法的具体用法?PHP Roles::insert怎么用?PHP Roles::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = \Faker\Factory::create();
Roles::truncate();
$roles = [['name' => 'admin', 'display_name' => 'Administrator', 'discription' => 'Administrator', 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['name' => 'member', 'display_name' => 'Member', 'discription' => 'Member', 'created_at' => new DateTime(), 'updated_at' => new DateTime()]];
foreach ($roles as $role) {
Roles::insert($role);
}
}
示例2: editAction
function editAction()
{
$request = new Bolts_Request($this->getRequest());
$roles_table = new Roles();
$role = null;
if ($request->has('id')) {
if (!is_null($request->id)) {
$role = $roles_table->fetchRow($roles_table->select()->where("id = ?", $request->id));
if (!is_null($role)) {
// we do not edit the guest role
if ($role->shortname == "guest") {
$this->_redirect("/bolts/role");
}
$this->view->role = $role->toArray();
$this->view->role_tree = $roles_table->getRoleTree(null, $role->id);
$this->view->inherited_ids = $roles_table->getInheritedRoles($role->id);
}
}
}
if (is_null($role)) {
$this->view->role_tree = $roles_table->getRoleTree();
}
if ($this->getRequest()->isPost()) {
$errors = array();
if ($request->has('inherit_role')) {
$parents = array();
foreach ($request->inherit_role as $inherit_role) {
$parents = array_merge($parents, $roles_table->getAllAncestors($inherit_role));
}
$inherit_ids = array();
foreach ($request->inherit_role as $inherit_role) {
if (!in_array($inherit_role, $parents)) {
$inherit_ids[] = $inherit_role;
}
}
}
if ($request->has('shortname')) {
$shortname = $request->shortname;
if (!Bolts_Validate::checkLength($request->shortname, 1, 255)) {
$errors[] = $this->_T("Shortname must be between 1 and 255 chars.");
}
} else {
$errors[] = $this->_T("Shortname is a requried field.");
}
$description = $request->description;
$isadmin = (int) $request->checkbox('isadmin');
if (count($errors) == 0) {
$data = array('shortname' => $shortname, 'description' => $description, 'isadmin' => $isadmin);
//If we have an id, this is an update.
$id = (int) $this->_request->getPost('id');
if ($id != 0) {
$where = 'id = ' . $id;
$roles_table->update($data, $where);
} else {
//We don't, this is an insert.
$id = $roles_table->insert($data);
}
$roles_table->removeInheritedRole($id);
foreach ($inherit_ids as $in_id) {
$roles_table->setInheritedRole($id, $in_id);
}
$this->_redirect("/bolts/role");
} else {
$this->view->errors = $errors;
}
}
if ($request->has('id')) {
// this is an edit
$id = $request->id;
if ($id > 0) {
$this->view->role = $roles_table->fetchRow('id = ' . $id)->toArray();
}
$this->view->inherited_ids = $roles_table->getInheritedRoles($id);
} else {
foreach ($roles_table->fetchAll()->toArray() as $role) {
$role_choices[$role['id']] = $role['shortname'];
}
$this->view->role_choices = $role_choices;
}
}