簡體   English   中英

頁面加載錯誤代碼點火器

[英]Page load error codeigniter

可提供保留域名列表的小型codeigniter項目。 登錄頁面后,您將從數據庫重定向到域列表。 運行此頁面(Doamins列表),沒有問題。 唯一的問題是當您從登錄名調用此頁面時。 登錄頁面沒有問題(下面的登錄控制器)。

public function index(){
    $this->load->view('login');
}
public function checklogin()
{
    $this->form_validation->set_rules('username','Username','required');
    $this->form_validation->set_rules('password','Password','required|callback_verifyUser');

    if($this->form_validation->run() == false){
        $this->load->view('login');
    }else{
        $this->load->view('home');
    }
}
public function verifyUser(){
    $User = $this->input->post('username');
    $Pwd = $this->input->post('password');

    $this->load->model('Loginmodel');
    if($this->Loginmodel->login($User,$Pwd)){
            return true;
    }else{
         $this->form_validation->set_message('verifyUser','Incorrect Login Details');   
         return false;
    }
}

調用“ home”索引似乎是問題所在(下面的代碼) 主頁模型

public function getPosts()
{
    $result = array();
    $this->db->select('*');
    $this->db->from('domains');
    $this->db->where('Active','Y');
    $this->db->order_by('ExpDate','ASC');
    //$query= $this->db->query("select * from baldwin_domains where Active ='Y' order by ExpDate ASC");
    $query = $this->db->get();
    if($query->num_rows()>0){
        return $query->result();
    }
}

主頁控制器:

public function index()
{
    $this ->load->model('Crudmodel');
    $records = $this->Crudmodel->getPosts();
    $this->load->view('home', ['records' => $records]);
}

刪除登錄名,所有頁面都可以正常工作。 這是錯誤:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: records

Filename: views/home.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\domainsys\application\views\home.php
Line: 17
Function: _error_handler
File: C:\xampp\htdocs\domainsys\application\controllers\Login.php
Line: 15
Function: view
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/home.php
Line Number: 17
Backtrace:
File: C:\xampp\htdocs\domainsys\application\views\home.php
Line: 17
Function: _error_handler
File: C:\xampp\htdocs\domainsys\application\controllers\Login.php
Line: 15
Function: view

問題是,當用戶輸入有效憑據時,您將加載視圖home 但是您沒有將任何參數傳遞給視圖。

通過查看主頁控制器,我假設您正在Home上呈現帖子列表( Home視圖)。 因此,除了加載視圖之外,您必須將他重定向到主控制器。

登錄后嘗試使用redirect('home','refresh')而不是$this->load->view('home')

public function checklogin()
{
    $this->form_validation->set_rules('username', 'Username','required');
    $this->form_validation->set_rules ('password','Password','required|callback_verifyUser');

    if($this->form_validation->run() == false){
        $this->load->view('login');
    }else{
        redirect('home','refresh');
    }
}

重定向將他帶到家庭控制器並呈現所需的內容。

public function index()
{
    $this ->load->model('Crudmodel');
    $records = $this->Crudmodel->getPosts();
    $this->load->view('home', array('records' => $records));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM