0
votes

Hi friends I'm new to CodeIgniter, I've downloaded version 3.04 and in controller page i've created parent constructor .

Controller :

class Vote extends CI_Controller {
public function construct(){
parent::__construct();
$this->data['theme'] = 'admin';        
}
public function index()
{        
$this->data['page'] = 'login_page';
$this->load->vars($this->data);
$this->load->view($this->data['theme'].'/template');
}

Error :

A PHP Error was encountered

Severity: Notice

Message: Undefined index: theme

Filename: controllers/vote.php

Line Number: 30

Backtrace:

File: C:\xampp\htdocs\poll\application\controllers\vote.php Line: 30 Function: _error_handler

File: C:\xampp\htdocs\poll\index.php Line: 292 Function: require_once

Why do I get an error like this I have added $autoload['helper'] = array('url'); also.

1
change this $this->load->view($this->data['theme'].'/template'); to $this->load->view($this->data.'/template'); and try - Pathik Vejani
@PathikVejani :A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: controllers/Vote.php - Navaneetha Krishnan K

1 Answers

0
votes

First create a file called MY_Controller.php under application/core folder. In this file, you should create a class. E.g:

class Some_class extends CI_Controller {
public function __construct() {
parent::__construct();
$this->data['theme'] = 'admin';
 }
}

Than edit your Controller like below:

class Vote extends Some_class {
public function construct(){
parent::__construct();
}
public function index()
{        
$this->data['page'] = 'login_page';
$this->load->vars($this->data);
$this->load->view($this->data['theme'].'/template');
}