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');
}
}
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);
}
}
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.
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
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.
Related
I have some problem with CodeIgniter 3.
When I try to access URL with the parameter like these http://localhost/crm/Customer/update/3
The result is infinite loop page refresh.
This does not happen if I access other view or URL.
For example : http://localhost/crm/Customer/list
Below is my controller file :
class Customer extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url', 'customer'));
$this->load->database();
$this->load->library('session');
$this->load->model(array('Auth', 'Model_customer'));
$this->_init();
}
function _init() {
$this->output->set_template('index');
// $this->load->section('sidebar','template/sidebar');
}
public function index(){
...
$this->load->view('customer/index');
}
function update($id) {
// TEST
$data['id'] = $id;
$this->load->view('customer/update2', $data);
}
}
Any help will be valuable. Thanks
Am trying to load view file in application/core/MY_Controller.php but its giving as follows.
Message: Undefined property: Edustaticlanding::$load
Filename: core/MY_Controller.php
Function is as follows in MY_Controller.php
function menu(){
$arrr = array();
return $arrdata['menu'] = $this->load->view('menu',$arrr,true);
}
And am calling this function in controller(Edustaticlanding.php) as follows.
function __construct(){
$this->menucontent = $this->menu();
print_r($this->menucontent); die;
}
Pls correct me.. where its going wrong.. thanks
On application/core/MY_Controller.php
Add public $data = array() like below
<?php
class MY_Controller extends CI_Controller
{
public $data = array();
public function __construct()
{
parent::__construct();
$this->data['menu'] = $this->menu();
}
public function menu(){
return $this->load->view('menu', NULL, TRUE);
}
}
On the controller then once add public $data = array(); you can access the menu on view
You have to use $this->data now on controller
<?php
class Example extends MY_Controller {
public $data = array();
public function index() {
$this->data['title'] = 'Welcome to Codeigniter';
$this->load->view('example', $this->data);
}
}
On the example view now you can echo
<?php echo $menu;?>
Add extends CI_Controller to your core controller like following codes:
class MY_Controller extends CI_Controller {
Please check below mentioned solution. You need to call parent constructor first. So it will load all basic configurations.
First extent CI_Controller class and call parent constructor like describe below
class MY_Controller extends CI_Controller {
public function __construct{
parent::__construct();
}
}
Please let me if it not works.
I'm sure this is a simple mistake on my part. I'm trying to demo ci to a friend and we created a simple controller that looks like this:
<?php
class Customerlookup extends CI_Controller {
//constructor for this class
public function __construct()
{
parent::__construct();
$this->load->model('customerlookup_model');
}
public function index()
{
echo 'test';
}
public function loadcustomers()
{
$data['cust'] = this->customerlookup_model->get_customers();
$this->load->view('customerlookup',$data);
}
}
And here's what the model looks like:
<?php
class Customerlookup_model extends CI_Model
{
public function __construct()
{
parent::Model();
$this->load->database();
}
public function get_customers()
{
$query = $this->db->get('customer');
return $query->result_array();
}
}
If I try to test this out by doing either:
localhost/myapp/index.php/customerlookup/loadcustomers
or
localhost/myapp/index.php/customerlookup/
nothing happens and no errors appear and no data or messages either. We are using the latest CodeIgniter (2.1.3).
Any suggestion?
i found the problem. php errors were not turned on. there were some syntax problems. checked the apache error log and figured out that the errors were just not being displayed
thanks for the help guys
you are missing with your url helper
$this->load->helper('url');
into your
class Customerlookup extends CI_Controller {
//constructor for this class
public function __construct()
{
parent::__construct();
$this->load->model('customerlookup_model');
$this->load->helper('url');
}
public function index()
{
echo 'test';
}
public function loadcustomers()
{
$data['cust'] = this->customerlookup_model->get_customers();
$this->load->view('customerlookup',$data);
}
}
I want to declare a variable in a php class which can be used in all its functions. I am using the codeigniter framework & to have to pass data like base_url etc in each of the functions. Also I need all of such data in a single variable. For example $data['base_url']=base_url(), $data['title']="My_Site_title" etc & then send only a single variable $data (this is a common thing in codeigniter).
As per this question, I modified my code to:
class Search extends CI_Controller {
function Search() {
parent::__construct();
$this->load->model('student_model');
$this->load->helper('form');
$this->load->helper('url');
$this->output->enable_profiler(TRUE);
$this->data['base_url']=base_url(); //gives an error here
}
function index() {
$this->load->view('search_view', $this->data);
}
}
But still it gives an error at the marked place saying Undefined variable: data and Fatal error: Cannot access empty property in ..\search.php on line 16.
Here you go:
class Search extends CI_Controller {
protected $data = array();
function Search() {
parent::__construct();
$this->load->model('student_model');
$this->load->helper('form');
$this->load->helper('url');
$this->output->enable_profiler(TRUE);
$this->data['base_url']=base_url();
}
function index() {
$this->load->view('search_view', $this->data);
}
}
More about class properties in php: http://php.net/manual/en/language.oop5.properties.php
Using CodeIgniter 2.0.3 on XAMPP 1.7.7 I have code where I get the error as: Unable to load the requested file: home.php
The home.php code as follows stored in ./ci2/application/controllers:
class Home extends CI_Controller {
function Home()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
While using it just notice:
controller's name is home.php
File named home.php must be present in ci/views
Incase file extention in view folder is not php eg like its html.
then load it using : $this->load->view('home.html');
the function u need to call from outside must be public So make it:
public function index() {... }
as u are calling the constructor for the class Home. Call it like:
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home');
}
Now it will work !
Your call to $this->load->view('home'); will be looking for home.php in /ci2/application/views/. That's the file it can't find.
I'm assuming you're calling http://myapp/index.php/home/ - that means it'll automatically call the index() method.
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
}
Please check the name of the file you have created in application/views/, because otherwise the code is correct.