Objective:
To enable one user to manage multiple stores
Example:
There is a user A, he is given the store ID 1 and 2 of the store's administrative rights.
Then he can manage the backstage when he accesses the ^/SHOP/1 and ^/SHOP/2 paths of the store. When he visited the ^/SHOP/3 store, he did not have background access functionality.
- How should this function be implemented?
- If you have the relevant English information, directly to my connection is OK.
- Or recommend to me a few English search keywords
Thank you
Reply content:
Objective:
To enable one user to manage multiple stores
Example:
There is a user A, he is given the store ID 1 and 2 of the store's administrative rights.
Then he can manage the backstage when he accesses the ^/SHOP/1 and ^/SHOP/2 paths of the store. When he visited the ^/SHOP/3 store, he did not have background access functionality.
- How should this function be implemented?
- If you have the relevant English information, directly to my connection is OK.
- Or recommend to me a few English search keywords
Thank you
Key words: Paramconverter,acl
Set: Your store is using a doctrine entity, such as
namespace YourBundle\Entity;class Store{ // ...}
Code:
// 在你的Controller里,先引入你的Store类:use YourBundle\Entity\Store;// 再引入SensioFrameworkExtraBundle(Symfony 2默认包含)的ParamConverter注解:use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;// 再引入JMSSecurityExtraBundle(Symfony 2默认包含)的SecureParam注解:use JMS\SecurityExtraBundle\Annotation\SecureParam;class YourController{ /** * 通过ParamConverter,将router里的id(或别的placeholder,注意,默认是取id)值作为主键来实例化为一个Store对象 * @ParamConverter("store", class="YourBundle:Store", options={"id"="id"}) * 这里指要求当前用户对$store参数,拥有OWNER权限 * @SecureParam(name="store", permissions="OWNER") */ public function someAction(Store $store) { // ... }}
How to enable users to have Owner permissions on $store objects, refer to: http://symfony.com/doc/current/cookbook/security/acl.html