Welcome Guest, Not a member yet? Register   Sign In
Output buffering error... But why?
#1

[eluser]stormbytes[/eluser]
I'm trying to error-trap the details() method below, so that prior to outputting a view, it checks (against the database) to see if the args are valid. First it checks to see if args have been provided altogether, and if not, it redirects the user to the catalog() controller. This part works fine, which is all the more baffling!

Next, it checks to see if the details() method's args are indeed valid by calling a model-method. This is the part that generates an error. I don't understand why this is happening as the $this->load->view statement only appears if BOTH conditions are not met. So as far as I see it, there's no output prior to that.

Error Message:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: models/assets_mod.php

Line Number: 43
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Users/iMac/Dropbox/htdocs/bin/ci_arrow/system/libraries/Exceptions.php:166)

Filename: helpers/url_helper.php

Line Number: 539

Class Method details()

Code:
function details($asset_id = array()) {
        
        if(!count($asset_id) > 0) {
            redirect(base_url(). 'catalog', 'refresh');
        } elseif(!$this->assets_mod->get_asset_url($asset_id)) {
        
            redirect(base_url(). 'catalog', 'refresh');
        } else {

            // Page Defaults
            $data['page_title']       = "Details";
            $data['page_desc']        = $this->assets_mod->get_asset_name($asset_id);
            $data['asset_url']        = $this->assets_mod->get_asset_url($asset_id);
            $data['content']          = 'view_asset';
            
            $this->load->view('template', $data);
        }
    }
model-Method get_asset_url()
Code:
function get_asset_url($asset_id) {
        
         if(count($asset_id) == 1) {

            $q = $this->db->select("asset_url");
            $q = $this->db->where("asset_id", $asset_id);
            $q = $this->db->get("Assets", 1);

            if($q->num_rows() == 1)
             foreach($q->result() As $row)
                $data = $row->asset_url;
            
            return $data;}
        
        else {
            return FALSE;
        }
    }
#2

[eluser]cahva[/eluser]
As I dont know exatcly what goes on in the rest of your controller, I assume the method's parameter should not be an array. Also I think you should just get the row with all the fields you need in one go from model.

Try this(I dont know if it will work as I said I dont know the big picture).

asset_mod model:
Code:
function get_asset($asset_id = FALSE)
{
    if (!$asset_id)
    {
        return FALSE;
    }
    
    $row = $this->db->where('asset_id',$asset_id)->get('Assets')->row();
    
    return $row; // will return FALSE if not found
}

details method from your controller:
Code:
function details($asset_id = FALSE)
{
    if (!$asset_id)
    {
        redirect('catalog');
    }
    
    $asset = $this->assets_mod->get_asset($asset_id);
    
    if (!$asset)
    {
        redirect('catalog');
    }
    
    $data = array(
        'page_title' => 'Details',
        'page_desc' => $asset->page_desc,
        'asset_url' => $asset->asset_url,
        'content' => 'view_asset'
    );
    
    $this->load->view('template', $data);
}

Was this what you were after?
#3

[eluser]stormbytes[/eluser]
Beautiful -

Yeah, pretty much.

That's what I love about asking questions on the CI forum - You learn a lot more then just the solutions to your problem. I'll refactor some of my classes applying your technique. Clean, simple and much more efficient use of code!

Thanks for the lesson -
#4

[eluser]stormbytes[/eluser]
Been fiddling with this code...

Haven't seen '->row()' appended to a query like that before. What exactly does this function return? (array, resource, etc)

How would use use this in the View?

EDIT -

NM, got it. User Guide is my friend!




Theme © iAndrew 2016 - Forum software by © MyBB