Welcome Guest, Not a member yet? Register   Sign In
Method chaining problem
#1

[eluser]Replenish[/eluser]
Im getting an error when I try to use method chaining to return the extension that is stored in the database. The method chain is supposed to get the extension out of the row that has the 'original' value of $image. Im not sure if im doing it right.

Code:
Code:
$image = $this->uri->segment(3,0);

$this->db->select('extension')->from('pix')->where('original', $image);

$query = $this->db->get();

echo $query;
Error:
Quote:Fatal error: ob_start() [<a href='ref.outcontrol'>ref.outcontrol</a>]: Cannot use output buffering in output buffering display handlers in C:\WebServer\htdocs\system\libraries\Exceptions.php on line 160

Any help would be appreciated
#2

[eluser]coolfactor[/eluser]
Are you sure the problem is related to method chaining? Are you running PHP 5, which is required for method chaining to work?

The error you posted doesn't say anything about method chaining, so I'm curious how it's related.
#3

[eluser]Replenish[/eluser]
Yeah im running PHP 5, and I only get the error when I try to take the value the method chain returns and delcare it.
#4

[eluser]Michael Wales[/eluser]
It's because you are echoing out to the controller (and GZip compression is enabled). Assign it a variable, pass that to a view, then echo it from the view (as MVC is supposed to) and everything will be okay.

This error doesn't really mean anything and won't stop execution - it just means the server couldn't compress the data prior to sending to the client.
#5

[eluser]Replenish[/eluser]
Ok so I changed a few things around.

Controller:
Code:
$image = $this->uri->segment(3,0);

$this->db->select('extension')->from('pix')->where('original', $image);

$query = $this->db->get();

$data['image'] = $image;
$data['ext']   = $query;

$this->load->view('front/uploaded', $data);

View:
Code:
<div>
&lt;?=$image;?&gt;
&lt;?=$ext;?&gt;
</div>

The view spits out
Code:
3b1f98c3bb55e2aa24c8a39b5eb77e64 <--($image)
A PHP Error was encountered

Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: front/uploaded.php

Line Number: 34

I've read over the query stuff in the user guide and i'm still at a loss :|
The table has columns as follows: id, original, height, width, original_path, extension
#6

[eluser]deviant[/eluser]
It's because you are trying to echo object that get() returns, which you can't do. Try either of these

Code:
$result = $query->first_row['array'];

$data['ext'] = $result['extension'];

or

Code:
$result = $query->first_row();

$data['ext'] = $result->extension;
#7

[eluser]Replenish[/eluser]
My god that worked! Thanks :>




Theme © iAndrew 2016 - Forum software by © MyBB