CodeIgniter:如何从模型向控制器发送数组,然后查看

时间:2014-12-24 04:01:01

标签: php arrays codeigniter

我有以下型号:

            // Session info in $session array.
            $session = $query->row_array();
            $userid = $session['uid'];
            $uq = $this->db->query("SELECT * FROM `administration_users` WHERE id = $userid");

            $now = strtotime(date("m/d/Y h:i:s A"));
            if($session['terminatedate'] > $now) {

                // If Session is STILL ACTIVE, let's give them an additional hour. Have fun!

                $newterm = $now + 3600;

                $userq = $uq->row_array();
                $username = $userq['username'];
                $userfull = $userq['name_first'] . " " . $userq['name_last'];

                $this->ELog->authentication('INFORMATION',$username,"Session for $userfull has been extended by 3600 seconds (1 hour) due to activity in application.");

                $this->db->query("UPDATE `administration_sessionkeys` SET terminatedate='$newterm' WHERE id='$session[id]'");

            } elseif($session['terminatedate'] < $now) {

                // If Session is OVER...

                $userq = $uq->row_array();
                $username = $userq['username'];
                $userfull = $userq['name_first'] . " " . $userq['name_last'];

                $this->ELog->authentication('INFORMATION',$username,"$userfull has been logged out automatically by AuthLogger due to session timeout. Thanks for stopping by. Goodbye!");

                $this->db->query("UPDATE `administration_sessionkeys` SET `terminated`='1',`terminated_details`='Session Ended. Thanks for stopping by. Goodbye!' WHERE id='$session[id]'");
                setcookie("ssmp_auth_cookie_uid", "", time() - 3600);

                return false;

            }

            $userinfo[] = $uq->row_array();
            return array($userinfo);

我的控制器,看起来像这样:

    $this->load->model('Auth_model', "", TRUE);
    $data = array($this->Auth_model->authcheck());

    if(!$data) {
        header("Location: /auth/login");
    } else {

    $this->load->view('tmpl/header', $data);
    $this->load->view('dashboard', $data);
    $this->load->view('tmpl/footer', $data);

    }

我的观点是这样的,这里的问题是我无法从视图中的模型访问我的数组。我究竟做错了什么?我现在已经在这上面了3个小时。我需要休息和一些帮助。

<title>Logged into SSMP as <?=$id;?></title>

这应该给我数组中的“id”列,对吗?没有?

请帮帮我,对不起这么多代码,我不确定你们需要看到什么来帮助我。

感谢所有能够为这个恼人的问题提供帮助的人。

斯科特

2 个答案:

答案 0 :(得分:0)

row_array()已经返回一个关联数组,所以你不需要再次将结果包装在一个数组中

变化

$userinfo[] = $uq->row_array();
return array($userinfo);

$userinfo = $uq->row_array();
return $userinfo;

答案 1 :(得分:0)

更改以下内容:

$userinfo[] = $uq->row_array();
return array($userinfo);

到:

return $uq->row_array();

和:

$data = array($this->Auth_model->authcheck());

到:

$data['administration_users'] = $this->Auth_model->authcheck();

在您查看文件中:

<title>Logged into SSMP as <?php echo $administration_users['id']; ?></title>

提示:使用重定向帮助程序进行重定向:

if(!$data) {
  // header("Location: /auth/login");
  // Assuming that you have url_helper already loaded,
  // if not, uncomment the next line :
  // $this->load->helper('url');
  redirect('auth/login');