Search code examples
phpyiiyii-extensions

Yii : how to call rights's model from another controller


Q : how do I retrieve the data at user/admincontroller of user extension from a table (authitem) of rights extension.

status : I am using rights and users extension. Both extensions are working fine by separately.

This is my code

$roles = AuthItem::model()->findAll('type=2');

This is my main.php

'import'=>array(

        'application.models.*',
        'application.components.*',

        // user extenstion

        'application.modules.user.models.*',
        'application.modules.user.components.*',


        // rights extensions
        'application.modules.rights.*', 
        'application.modules.rights.components.*', // Correct paths if necessary.
    ),

This is error msg

include(AuthItem.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Solution

  • Turns out, you can't do that, you can;t access use AuthItem as model and retrieve information from it..

    I faced this problem in last project where I used Rights, and needed all users of a particular role, needed a dropdown of all roles, from which admin can choose, all roles assigned to a user, etc requirements..

    I wrote a good blog post having solution for such quesitions..

    One of them, which seems to be your case is:

    Generate Check-Boxes of all available roles in the application..

    <?php
       $all_roles=new RAuthItemDataProvider('roles', array('type'=>2));
       $data=$all_roles->fetchData();
    ?>
    <div>
        <label for="type_id">Type</label>
        <?php echo CHtml::checkBoxList("Type",'',CHtml::listData($data,'name','name'));?> 
    </div>
    

    You can find complete blog post here