fuel / parser

Fuel PHP Framework - v1.x template parser package adapters
http://fuelphp.com
64 stars 45 forks source link

Database results are read-only using Parser\View #11

Closed kavinsky closed 13 years ago

kavinsky commented 13 years ago

Trying to upgrade a existing project for use Parser package give this error: http://oi53.tinypic.com/2sb8jzm.jpg

Always when u try to pass a Database_Result into a var like this:

$data['rows'] = \DB::select('*')
                    ->from('table')
                    ->execute();

$this->response->body = View::factory('view', $data);

If i deactive Parser package that dosent happens.

Im using develop branch of fuel.( upgraded from rc1> rc2>rc3) Greetz.

jschreuder commented 13 years ago

Has nothing to do with the Parser package.

The Database returns an immutable result, but if you add it to the view it will be output encoded which will cause the error you gave as the result object is immutable.

You have to either pass the DB result unchecked or pass it in a mutable form:

// option 1: pass it mutable
$data['rows'] = \DB::select('*')
                    ->from('table')
                    ->execute()->as_array();
$this->response->body = View::factory('view', $data);

// option 2: pass it unchecked
$this->response->body = View::factory('view');
$this->response->body->set('rows', \DB::select('*')
                    ->from('table')
                    ->execute(), false);
mettjus commented 12 years ago

What's wrong with this code, plz?

$data['rows'] = DB::query('SELECT * FROM table_name')->as_object()->execute(); $this->response(View::forge('search/results', $data));

Thanks, Mat

jschreuder commented 12 years ago

How do you expect anyone to help you without giving the error? And why do you ask support in the issue tracker? That's what the forums are for.