0

My controller page is:

class Anasayfa extends CI_Controller {

public $viewData;

function __construct() {
    parent::__construct();
    $this->viewData = new stdClass();
    $this->viewData->sayfa = 'main';
}

public function index()
{
    $this->load->view('common/template', $this->viewData);
}

My view page is:

$this->load->view('common/header'); $this->load->view('common/navbar'); $this->load->view('common/solmenu'); $this->load->view('common/slider'); $this->load->view($sayfa); $this->load->view('common/footer');

But in browser:

Severity: Notice

Message: Undefined variable: sayfa

Filename: common/template.php

Line Number: 6

2 Answers 2

2

Use an array:

function __construct() {
    parent::__construct();
    $this->viewData = array();
    $this->viewData['sayfa'] = 'main';
}
Sign up to request clarification or add additional context in comments.

Comments

0

Pass an array instead of object:

$this->viewData['sayfa'] = 'main';

Adding Dynamic Data to the View.

2 Comments

it's possible but i want to this $this->viewData->sayfa = 'main';
Not in CodeIgniter until you change core class(es) in system directory which is never good solution (updating framework, compatibility with other CI packages, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.