0
votes

I was passing my arguments correctly by URL and then I don't know what's wrong with the variables

Message: Missing argument 1 for Welcome::index()

Filename: controllers/Welcome.php

Line Number: 10

Backtrace:

File: /var/www/html/proyecto/application/controllers/Welcome.php Line: 10 Function: _error_handler

File: /var/www/html/proyecto/index.php Line: 292 Function: require_once

Controller:

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');
    }

}
4
May be in routes you need to configure something like $route['welcome/(:any)'] = 'welcome/index/$1'; codeigniter.com/user_guide/general/routing.html - Mr. ED
And then try index($password = NULL) or something because $password I think would be a uri segment. http://localhost/index.php/welcome/1234 - Mr. ED
why if I add password = null works and if I dont add NULL not works? - user5802782
Aron, if you add password = null you're setting the default value for the variable. So if you don't add it as a parameter on the function call, there won't be problem because there is already a value to it. - Phiter

4 Answers

0
votes

you need to pass the pariable to view page? Then use this code

 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);
        }

}
0
votes

Your controller need to accept one argument

public function index(**$password**)

so you need to define what $password coming from.

or you just edit your controller

public function index($password = "") 

to avoid the warning.

0
votes
 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);
        }

}

Thanks angel and weirdo

0
votes

You should check your requested url. You may see the reference here in the "Passing URI Segments to your Functions" section.

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');
    }
}

From your code above, you create a required $password variable for each request. So you must put a value in the end of your url for the password. i.e. example.com/index.php/Welcome/index/password

I hope this help. thank you.