English 中文(简体)
检索 IonAuth - Compigniter 中的用户群代号
原标题:Retrieve the group id of user in Ion Auth - Codeigniter

我用扬·阿特斯来申请我的代码应用,除了一件事,一切都看起来不错。

我需要显示一个用户列表以及他们所在的组。 我怎样才能在不制作自己的模型和查询的情况下检索到特定用户的组代号 。 @ info: whatsthis

$This- gt; ion_ auth- gt; user( $id)- & gt; row (); 没有检索组 id 。

问题回答

Ion Auth 更新并删除了最新版本中的 < get_user 函数。 因此, 以下应返回当前在用户中登录的组代号 :

$this->ion_auth->get_users_groups()->row()->id

如果您想要获得特定用户的组代号, 您可以将用户代号传送到 < 坚固> get_ user_ groups 方法中 。

获取对象:

$user_groups = $this->ion_auth->get_users_groups($user->id)->result();

Get the group name: 获取组名称 :

$this->ion_auth->get_users_groups($data[ id ])->row()->name;

在我看来:

$data[ groups ] = $this->ion_auth->get_users_groups($data[ id ])->row()

您可以查看关于获取用户群的外部文件 :

http://bedemunds.com/ion_auth/#get_uses_groups

我发现这个是因为我想在成功登录时在会场上加入用户群 。 如果有人感兴趣,请看看我是如何做到的(一旦我设法弄清楚了所有事情都在哪里完成 ) 。

在 ion_auth_ model.php 中, 我选择了设置- session 函数 :

    public function set_session($user)
{

    $this->trigger_events( pre_set_session );

    $session_data = array(
         identity              => $user->{$this->identity_column},
         username              => $user->username,
         email                 => $user->email,
         user_id               => $user->id, //everyone likes to overwrite id so we ll use user_id
         old_last_login        => $user->last_login
    );

    $this->session->set_userdata($session_data);

    $this->trigger_events( post_set_session );

    return TRUE;
}

并把它修改为:

    public function set_session($user)
{

    $this->trigger_events( pre_set_session );

    $session_data = array(
         identity              => $user->{$this->identity_column},
         username              => $user->username,
         email                 => $user->email,
         user_id               => $user->id, //everyone likes to overwrite id so we ll use user_id
         old_last_login        => $user->last_login
    );

    //get user group ids for user and pass to session
    $groups = $this->ion_auth->get_users_groups($user->id)->result();

    foreach ($groups as $row){
        $session_data[ groups ][] = $row->id;
    }

    $this->session->set_userdata($session_data);

    $this->trigger_events( post_set_session );

    return TRUE;
}

现在它写一个阵列到会话中被称为组的会话。 组名是用户所属的所有组的列表 。

我唯一要做的其他事情是修改 Ion_auth.php 中的登出功能(在应用程序/图书馆中),以确保分组会话变量通过添加

$this->session->unset_userdata( groups );

转到其他未设置的用户数据()报表列表。

我知道我也许应该 仅仅扩展图书馆/模范 使核心保持不动, 但你可以采取我做什么 并且容易做到这一点。

希望这能帮到人

罗伯

Try adding this to ion_auth_model.php (Or place the query somewhere else)

/**
 * get_all_users_with_group
 *
 * @return array
 **/
public function get_all_users_with_group()
{
    $this->trigger_events( get_all_users_with_groups );

    return $this->db->select(
        $this->tables[ users ]. .*,  .
        $this->tables[ users_groups ]. . .$this->join[ groups ].  as group_id,  .
        $this->tables[ groups ]. .name as group_name,  .
        $this->tables[ groups ]. .description as group_desc 
        )
    ->join($this->tables[ users_groups ], $this->tables[ users_groups ]. . .$this->join[ users ]. = .$this->tables[ users ]. .id )
    ->join($this->tables[ groups ], $this->tables[ users_groups ]. . .$this->join[ groups ]. = .$this->tables[ groups ]. .id )
    ->get($this->tables[ users ]);
}

控制器中的用途 :

$groups = array(1,2,3,4);
            $this->data[ list_staff ] = $this->ion_auth->users($groups)->result(); // выбираем всех teachers из зарегистрированных пользователей
            foreach ($this->data[ list_staff ] as $k => $one_staff)
            {
                $this->data[ list_staff ][$k]->groups = $this->ion_auth->get_users_groups($one_staff->id)->result();
            } 

在视图使用中:

<?php foreach($list_staff as $one):?> 
    <?php foreach ($one->groups as $group):?>
                                    <?php echo $group->description;?>,
                                <?php endforeach?> 
<?endforeach;?> 

but what about query to get groups for current logged in user (for example in my profile) I find next decision. Controller: $this->data[ this_user_groups ] = $this->ion_auth->get_users_groups()->result(); and view just:

<?php foreach ($this_user_groups as $group):?>
                                <?php echo $group->description;?>,
                            <?php endforeach?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签