Sunday, 15 July 2012

php - Illuminate Class editing doesn't take effect -



php - Illuminate Class editing doesn't take effect -

i'm facing problem in code and, think, easier solution seems edit illuminate class of laravel framework.

so opened file wanted edit (public/laravel/framework/src/illuminate/http/response.php) , added method headers returns response headers :

public function headers() { homecoming $this->headers; }

but, edit doesn't seem applied because, when want use:

route::filter('cache.put', function($route, $request, $response){ $headers = $response->headers(); });

the call undefined method error thrown.

my question : how can edit laravel class ?

you should not editing code belongs laravel framework directly. you'll have problem updating framework later on. if managed create work way you're trying, has potential break whole project since laravel still using it's own response class, while seek utilize own.

you need check out docs facades here laravel way: http://laravel.com/docs/facades

in short, since response class calling facade, need replace laravel's response facade 1 of own, custom facade pointing own response class. this:

myresponsefacade.php:

<?php namespace myapp; class myresponsefacade extends \illuminate\support\facades\response { public static function make($content = '', $status = 200, array $headers = array()) { homecoming new myresponse($content, $status, $headers); } }

myresponse.php

<?php namespace myapp class myresponse extends \illuminate\http\response { public function headers() { homecoming $this->headers; } }

then in app.php, replace:

'response' => 'illuminate\support\facades\response',

with this:

'response' => 'myapp\myresponsefacade',

and done! whole laravel app should returning response own class, , can utilize rest of code same name response.

make sure configure autoload properly, , php artisan dump-autoload laravel can see new files though.

as side note, seems using laravel cloning framework project. check answers in here improve way: should download laravel every project?

php laravel laravel-4

No comments:

Post a Comment