tags:

views:

195

answers:

5

hi, i'm trying to learn codeigniter (following a book) but don't understand why the web page comes out empty.

my controller is

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
    }

    function index()
    { 
        $data['title'] = "Welcome to Claudia's Kids";
        $data['navlist'] = $this->MCats->getCategoriesNav();
        $data['mainf'] = $this->MProducts->getMainFeature();
        $skip = $data['mainf']['id'];
        $data['sidef'] = $this->MProducts->getRandomProducts(3, $skip);
        $data['main'] = "home";     
        $this->load->vars($data);
        $this->load->view('template');
    }

the view is:

<--doctype declaration etc etc.. -->
</head>
<body>
    <div id="wrapper">
        <div id="header">
            <?php $this->load->view('header');?>
        </div>

        <div id='nav'>
            <?php $this->load->view('navigation');?>
        </div>

        <div id="main">
            <?php $this->load->view($main);?>
        </div>

        <div id="footer">
            <?php $this->load->view('footer');?>
        </div>

    </div>
</body>
</html>

Now I know the model is passing back the right variables, but the page appears completely blank. I would expect at least to see an error, or the basic html structure, but the page is just empty. Moreover, the controller doesn't work even if I modify it as follows:

function index()
{ 
    echo "hello.";
}

What am I doing wrong? Everything was working until I made some changes to the model - but even if I delete all those new changes, the page is still blank.. i'm really confused!

thanks, P.


I've isolated the function that gives me problems. here it is:

function getMainFeature()
{
    $data = array();
    $this->db->select("id, name, shortdesc, image");
    $this->db->where("featured", "true");
    $this->db->where("status", "active");
    $this->db->orderby("rand()");
    $this->db->limit(1);
    $Q = $this->db->get("products");
    if ($Q->num_rows() > 0)
    {
        foreach($Q->result_arry() as $row)
        {
            $data = array(
                "id" => $row['id'],
                "name" => $row['name'],
                "shortdesc" => $row['shortdesc'],
                "image" => $row['image'] 
                );
        }
    }
    $Q->free_result();
    return $data;
}

I'm quite convinced there must be a syntax error somewhere - but still don't understand why it doesn't show any error, even if I've set up error_reporting E_ALL in the index function..

+1  A: 

First port of call is to run php -l on the command line against your controller and all the models you changed and then reverted.

% php -l somefile.php

It's likely that there is a parse error in one of the files, and you have Display Errors set to Off in your php.ini. You should set Display Errors on for development and off for production, in case you haven't already.

(Edit: in the example above you have missed off the closing } of the class. It might be that.)

p.g.l.hall
Error reporting is = E_ALL in php.ini. I am not familiar with command line - how do i do it?(the missing bracket was only a cut n paste error..)i've isolated a function in one of the models that generates the error (eg, if I take out that function, the controller kind of works, ie it outputs "hello"; Still however, the template is not loaded, but no errors appear!)
Patrick
No matter what you set error_reporting to, errors will still not be displayed on the screen if display_errors is off.
p.g.l.hall
Thanks, this solved it. Have set display_errors on and so I was able to see the error and fix it!
Patrick
A: 

Check codeigniter folder permissions

TermiT
add write permissions to "logs" folder
TermiT
permissions must be right, as everything was working earlier. it must be some error in the model, or somewhere else - the problem is that it doesn't display any errors, so I'm clueless..
Patrick
+1  A: 

Make sure error_reporting in index.php is set to E_ALL and post your code for the model in question.

After looking through your function I suspect it's caused by $this->db->orderby("rand()"); For active record this should be $this->db->order_by('id', 'random');

Note that orderby is deprecated, you can still use it for now but the new function name is order_by

Dyllon
A: 

Not sure, but it can be also caused by php's "display_errors" is set to false. You can change it in your php.ini file.

DCrystal
Voted down for copying part of my answer.
p.g.l.hall
p.g.l.hall, sorry i just didn't notice it...
DCrystal
A: 

If you have isolated to a function in a model why not post it so we may be able to spot the error.

Eric