Welcome Guest, Not a member yet? Register   Sign In
A Newbie question
#1

[eluser]CI Newbie Guru[/eluser]
Hi,

I have recently installed codeigniter but having few issues. I have searched the forum and have viewed video tutorial but cannot find what is wrong with my code/settings.

1) I have home.php controller in home folder under controllers (controllers->home->home.php). I have changed the default controller in routes.php to home/home but i get 404 error. If i copy the home.php controller directly under controllers folder and change it to 'home' in routes then it works fine. Can you please tell me what to do to make it use home/home controller.

2) In my home controller i get following error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: controllers/home.php

Line Number: 13


This is the code from home.php
Code:
<?php
class Home extends Controller {

    function Home()
    {
        parent::Controller();
        
    }
    
    function index()
    {
        $data ['header']         = $this->load->view('common/header', $data, TRUE);
        
        $this->load->view('homepage', $data);
    }
}

?>

It loads the header view fine and display the content of data['header'] on homepage view without any problems.

Can any one please tell me where i am going wrong.

Thanks
#2

[eluser]Tanque[/eluser]
Code:
$data ['header']         = $this->load->view('common/header', $data, TRUE);

this is the error... you are passing $data before it's set... look ...'common/header', $data'... where is this variable set?...
#3

[eluser]Sumon[/eluser]
here is a simplified version

Code:
$data = $some_query->result();
$output['content_main'] = $this->load->view('list_partial', $data, TRUE);
$this->load->view('templates/master_page', $output);

surely you not get any $data error.
#4

[eluser]Crafter[/eluser]
Try
Code:
$data ['header']   = $this->load->view('common/header');
$this->load->view('homepage', $data);
#5

[eluser]Tanque[/eluser]
lo q dice crafter es a lo q me refería... excelente, gran aporte...

what crafter told us is what i mean... great stuff...




Theme © iAndrew 2016 - Forum software by © MyBB