Welcome Guest, Not a member yet? Register   Sign In
How to you debug blank pages?
#1

[eluser]CheekyGeek[/eluser]
I've been working with CodeIgniter almost nonstop for the last couple of days and really like what I'm seeing in theory (and in tutorials, etc.). Had things working well when I was using just Controllers and Views, but now that I'm trying to use a Model, I'm back to confused and doing something wrong.

I had a problem with logging errors, due to the webserver user not having proper permissions on system/logs, so fixed that. My hope was that I would get some debugging information in the logs. The only errors I got had to do with not being able to fopen system/cache so I also gave the webserver user permissions to it. Now there is nothing getting written there, even when I get a blank page.

So I assumed that I need to turn on display_errors in my php.ini file. But even after turning that on (with error_reporting set to E_ALL) I get nothing.

How in the heck do you debug a blank page with no feedback of any kind? There must be something I don't have configured correctly so I can see where things are breaking. Anybody wanna throw me a bone?
#2

[eluser]EEssam[/eluser]
I believe you should post your code and perhaps someone can tell you what you're doing incorrectly.
#3

[eluser]CheekyGeek[/eluser]
I am a moron and forgot to restart Apache after my last php.ini edit.
I hope to be close to proficient enough to post my non-working code in the near future. Right now I feel I'm so far off that it would be humiliatingly embarrassing to show anyone.
:\
#4

[eluser]Derek Allard[/eluser]
Hey don't worry about it CheekyGeek. Happens to all of us. Take a look at error handling in CodeIgniter also.
#5

[eluser]CheekyGeek[/eluser]
Oh embarrassment be darned-to-heck. I've gotta get off the starting line somehow here. I hate asking questions but I'm really having problems even understanding the User Guide. I see the code, but have no context for where it is to be used (Active Record stuff for instance: Controller or Model?).

Here's what I've got: A mysql "users" table. Here's the model for it. I'm pretty sure the model code should be OK because I modified the code from this tutorial to match my table fields.

mdl_users.php
Code:
class Mdl_users extends Model {

    // We will give this model the following properties so they can be set dynamically from the controller
    var $user_id;
    var $username;
    var $password
    var $last_name;
    var $first_name;
    var $phone;
    var $email;
    var $org;
    var $admin;

    function Mdl_users() {

        // All models need to call the constructor of the parent Model class
        parent::Model();

    }

    function get() {

        // BEGIN FILTER CRITERIA CHECK
        // If any of the following properties are set before mdl_users->get() is called from the controller then we will include
        // a where statement for each of the properties that have been set.
        if ($this->user_id) {
            $this->db->where("user_id", $this->user_id);
        }

        if ($this->username) {
            $this->db->where("username", $this->username);
        }

        if ($this->password) {
            $this->db->where("password", $this->password);
        }

        if ($this->last_name) {
            $this->db->where("last_name", $this->last_name);
        }

        if ($this->first_name) {
            $this->db->where("first_name", $this->first_name);
        }

        if ($this->phone) {
            $this->db->where("phone", $this->phone);
        }

        if ($this->email) {
            $this->db->where("email", $this->email);
        }

        if ($this->org) {
            $this->db->where("org", $this->org);
        }

        if ($this->admin) {
            $this->db->where("admin", $this->admin);
        }
        // END FILTER CRITERIA CHECK

        // We will display our results in order by last name and then first name.
        $this->db->orderby("last_name, first_name");

        // This will execute the query and collect the results and other properties of the query into an object.
        $query = $this->db->get("users");

        // If you set users->user_id from your controller, then there will only be one row to return.
        if ($this->user_id) {
            return ($query->row());
        }

        // If mdl_users->users_id was not specified in the controller, then we will return the results as a result set.
        else {
            return ($query->result());
        }

    }

    function save() {

        // When we insert or update a record in CodeIgniter, we pass the results as an array:
        $db_array = array(
        "user_id" => $this->user_id,
        "username" => $this->username,
        "password" => $this->password,
        "last_name" => $this->last_name,
        "first_name" => $this->first_name,
        "phone" => $this->phone,
        "email" => $this->email,
        "org" => $this->org,
        "admin" => $this->admin);

        // If mdl_users->contact_id was set in the controller, then we will update an existing record.
        if ($this->users_id) {
            $this->db->where("users_id", $this->users_id);
            $this->db->update("users", $db_array);
        }

        // If mdl_users->users_id was not set in the controller, then we will insert a new record.
        else {
            $this->db->insert("users", $db_array);
        }

    }

    function delete() {

        // As long as mdl_contacts->contact_id was set in the controller, we will delete the record.
        if ($this->users_id) {
            $this->db->where("users_id", $this->users_id);
            $this->db->delete("users");
        }

    }

}

Here's the controller user.php
Code:
<?php
class User extends Controller {

    function User(){
        parent::Controller();
        $this->load->model("mdl_users");
        $this->load->scaffolding('users');
        $this->load->helper('url');
        $this->load->helper('form');
    }

    function index(){
        $data['title'    ]     = "Users Summary";
        $data['heading'    ]     = "Listing of all application users:";
        $this->load->database();
        $data['query'] = $this->mdl_users->get();

         [color=red]$this->load->view('all', $data);[/color]
    }
    
    function detail(){
        $data['title'    ]     = "User Detail";
        $data['heading'    ]     = "Edit user attributes:";
        
        $this->load->view('detail', $data);
    }
    
    function search(){
        
    
    
    
}
?>

I'm getting a "Parse error: syntax error, unexpected T_VARIABLE" in the line in red when I try to call localhost/CI/index.php/user/index
#6

[eluser]CheekyGeek[/eluser]
And here is the view all.php

Code:
<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
    <h1>&lt;?php echo $heading ?&gt;</h1>
    
    &lt;form method="POST" action=""&gt;
    <table cellspacing="3" border="0">
    &lt;?php foreach($query->result() as $row): ?&gt;
    <tr bgcolor="yellow" >
    <td>&lt;?php echo $row->username ?&gt;</td>
    <td>&lt;?php echo $row->password ?&gt;</td>
    <td>&lt;?php echo $row->email ?&gt;</td>
    <td>&lt;?php echo $row->org ?&gt;</td>
    <td>&lt;?php echo $row->phone ?&gt;</td>
    <td>&lt;?php echo anchor('user/detail/'.$row->id, 'Edit User Info'); ?&gt;</td>
    </tr>
    &lt;?php endforeach; ?&gt;
    </table>
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

I had this working fine when I was using just controller and view, but how to use the model I don't get.




Theme © iAndrew 2016 - Forum software by © MyBB