Welcome Guest, Not a member yet? Register   Sign In
[Solved] No output and not sure why
#1

[eluser]Unknown[/eluser]
Ok there is probably something simple that I'm missing but I've been trying to find it for hours and maybe a fresh set of eyes will help me out.

This is my first attempt at a project with CI 2.0

for a brief description of the project I basically want users to be able to create groups and choose whether they are public or private groups. This is the first part I've tried to get working which simply just find all the public groups and lists them. This isn't complete code just the foundation to get what I want which I can edit later to get more advanced functionality so any where here is my model

Filename: groups.php
Code:
<?php

class Groups extends CI_Model
{

    //php 5 constructor
    function __construct() {
        parent::Model();
    }
    
    function getPublic() {
        
        $q = $this->db->query("SELECT * FROM groups WHERE public = 1");
        if ($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
        return $data;
        }
    }

}

This is my controller
Filename: group.php
Code:
<?php


class Group extends CI_Controller {

    //php 5 constructor
    function __construct() {
        parent::Controller();
    }
    
    function index() {
        $this->load->model('groups');
        $data[rows] = $this->groups->getPublic();
        $this->load->view('group_view', $data);
    }
}

And finally my view
Filename: group_view.php
Code:
<h1>All Groups</h1>
&lt;?php foreach ($rows as $r): ?&gt;
    <div>
    &lt;? echo $r->id; ?&gt;<br />
    &lt;? echo $r->name; ?&gt;<br />
    &lt;? echo $r->desc; ?&gt;<br />
    &lt;? echo $r->public; ?&gt;<br />
    &lt;? echo $r->owner_id; ?&gt;<br />
    </div>
&lt;?php endforeach; ?&gt;

When I call the controller in the browser I get a completely blank page with no source... Thanks in advance for any help
#2

[eluser]Unknown[/eluser]
Ok I finally figured this out with a closer look at the user guide (and yes I did check the guide before but overlooked this particular part Tongue ) anyway all I had to do is put parent::__construct(); in the construct method




Theme © iAndrew 2016 - Forum software by © MyBB