繁体   English   中英

带有变量的代码初始化器中缺少参数

[英]missing argument in codeigniter with variables

我通过URL正确传递了参数,然后我不知道变量出了什么问题

消息:Welcome :: index()缺少参数1

文件名:controllers / Welcome.php

行号:10

回溯:

文件:/var/www/html/proyecto/application/controllers/Welcome.php行:10函数:_error_handler

文件:/var/www/html/proyecto/index.php行:292功能:require_once

控制器:

class Welcome extends CI_Controller {
    function __construct(){
        parent::__construct();
        $this->load->model('login_model');
    }

    public function index($password){

        $this->load->view('header');
        $this->load->view('index');
    }

}

您需要通过比喻来查看页面吗? 然后使用此代码

 class Welcome extends CI_Controller {
        function __construct(){
            parent::__construct();
            $this->load->model('login_model');
        }



 //value of password fetch to the variable $password
    //eg:$password='123';




 public function index($password){

            $this->load->view('header');
            $this->load->view('index',$password);
        }

}

您的控制器需要接受一个参数

public function index(**$password**)

因此,您需要定义$password来源。

或者你只是编辑你的控制器

public function index($password = "") 

避免警告。

 class Welcome extends CI_Controller {

        function __construct(){
            parent::__construct();
            $this->load->model('login_model');
        }


public function index($password = "") {

            $this->load->view('header');
            $this->load->view('index',$password);
        }

}

谢谢天使和怪人

您应该检查您要求的网址。 您可能会在“将URI段传递给函数”部分中看到参考

class Welcome extends CI_Controller {
    function __construct(){
       parent::__construct();
       $this->load->model('login_model');
    }

    public function index($password){

       $this->load->view('header');
       $this->load->view('index');
    }
}

从上面的代码中,您为每个请求创建一个必需的$ password变量。 因此,您必须在网址的末尾输入一个值作为密码。 即example.com/index.php/Welcome/index/password

希望对您有所帮助。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM