带有变量的编码点火器中缺少参数


missing argument in codeigniter with variables

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

消息:缺少欢迎的参数 1::index((

文件名:控制器/欢迎.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变量。因此,您必须在密码的 url 末尾放置一个值。即 example.com/index.php/Welcome/index/password

我希望这个帮助。谢谢。