1

I have this simple method in one of my objects:

public function action_buddy($name = 'buddy')
{
    $this->response->body = View::forge('hello', array(
        'name' => $name,
    ));
}

But I always get this warning and can't proceed futher:

Fuel\Core\PhpErrorException [ Warning ]: Creating default object from empty value

From this line:

$this->response->body = View::forge('hello', array(

How can I fix this warning?

p.s. I was following this tutorial http://code.tutsplus.com/tutorials/getting-started-with-the-fuel-php-framework--net-21334

Tachi
  • 2,042
  • 3
  • 27
  • 44
  • 2
    http://stackoverflow.com/questions/8900701/creating-default-object-from-empty-value-in-php – Alex Oct 12 '15 at 12:01
  • 1
    As @Alex pointed out it is because `$this->response` contains a `null` value. `$this->response` will only exist if something has created it. What is your controller extending? Is there a `before()` method that sets up `$this->response`? – Emlyn Oct 12 '15 at 12:57
  • My point is: there is the same question with chosen answer. That's the only thing I wanted to say. – Alex Oct 12 '15 at 13:47
  • As Uru said, there could be a parent controller, that sets up `$this->response` in `before` (or it should). So this could be a different question, though I also presume there's very little research effort in this question. @Tachi, as you can see, the exception is a `PhpErrorException`, so this is most probably NOT FuelPHP related. – Tamás Barta Oct 12 '15 at 13:53

1 Answers1

0

the tutorial you are using is really old, a lot of user also asked on that part. Anyway to answer your question, here it is:

    return View::forge('hello', array(
        'name' => $name,
    ));

OR

    // create the layout view
    $view = View::forge('hello');

    //local view variables, lazy rendering
    $view->name = $name;

    // return the view object to the Request
    return $view;

dont forget on your fuel/app/config/routes.php please comment

   //'hello(/:name)?' => array('welcome/hello', 'name' => 'hello'),

If you got bored with that tutorial, try this

http://ucf.github.io/fuelphp-crash-course/

+1 on your question, Enjoy Fuelphp!

mpalencia
  • 5,481
  • 4
  • 45
  • 59