"Shop"---role data maintenance

Source: Internet
Author: User

Controller:Rolecontroller operation method:showlist

Product List interface, in left.html

<table id=child{$v. auth_id} style= "Display:none" cellspacing=0 cellpadding=0 width=150 border=0>
{foreach $auth _infob as $kk = + $VV}
{* The PID of the child permission must be equal to the ID of the external permission *}
{if $vv. Auth_pid = = $v. auth_id}
<tr height=20>
<td align=middle width=30>

</td>
<td><a class= "Menuchild" href= "{$smarty. const.__module__}/{$vv. auth_c}/{$vv. auth_a}" target= "right" >{$VV .auth_name}</a></td>
</tr>
{/if}
{/foreach}
<tr height=4><td colspan=2></td></tr>
</table>
{/foreach}
</td>
<td width=1 bgcolor= #d1e6f7 ></td>
</tr>
</table>

1, show the list of roles,

Controller: Rolecontroller

Operation Method:showlist

Class Rolecontroller extends admincontroller{
Role List Display
function Showlist () {
Get role data, show data
$info = D (' Role ')->select ();
$this-Assign (' info ', $info);
$this, display ();
}

In showlist.html under the role module of view

{foreach $info as $k = + $v}
<tr id= "Product1" >
<td>{*[email protected]*}{$v .role_id}</td>
<td>{$v .role_name}</td>
<td>{$v .role_auth_ids}</td>
<td>{$v .role_auth_ac}</td>
<td><a href= "{$smarty. const.__controller__}/distribute/role_id/{$v. role_id}" > Assigning Permissions </a> </td> //pass role_id information to the distribute method to tell which role is currently assigned permissions
<td><a href= "" > Modify </a></td>
<td><a href= "" onclick= "> Delete </a></td>
</tr>
{/foreach}

2, assigning permissions to roles

Controller:Rolecontroller

Operation Method:Distribute

//Assign Permissions
function Distribute ($role _id) {
$role = new \model\rolemodel ();
//Two logic: show, collect
if (!empty ($_post)) {
//$_post data requires two production to be written to the database
//Create a method Saveauth in the custom Rolemodel to achieve data creation and storage
$z = $role->saveauth ($role _id,$_post[' auth_id ');
if ($z) {
$this-redirect (' Showlist ', Array (), 2, ' Assign permissions succeeded ');
}else{
$this-redirect (' Distribute ', Array (' role_id ' = ' + ' $role _id), 2, ' Assign permissions failed ');
}
}else{
//Query role information for assigned permissions
$role _info = $role->find ($role _id);

Permissions information already owned by the role
$have _auth = Explode (', ', $role _info[' role_auth_ids ');//Become an array

//Get all the permissions for the assignment and show it to the template
//top-level permissions, secondary top-level permissions
$auth _infoa = D (' auth ')- >where (' auth_level=0 ')->select ();
$auth _infob = D (' auth ')->where (' auth_level=1 ')- >select ();

$this-Assign (' Have_auth ', $have _auth);
$this-Assign (' Auth_infoa ', $auth _infoa);
$this-Assign (' Auth_infob ', $auth _infob);
$this-Assign (' Role_info ', $role _info);
$this, display ();
}
}
}

"Shop"---role data maintenance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.