Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Access View from inside View
  • How can I access the current View object from inside a View?
    I tried this:

    $this->get('somedata')

    but it threw an error.
    (Note that somedata may or may not be set and I want to avoid a wordy isset-construct)
  • There is no easy way, a view is rendered in a "sandbox" to avoid variable leaking.

    If 'somedata' is a variable set on the view, it's available in the view as $somedata.
  • OK, what would be the preferred alternative then? Does fuelphp provide a similar helper function?
    If I wrote one myself, where would I put it best?

  • The best practice answer is: if your view requires variables, make sure you pass them. If your view has optional variables, use isset() before you access them.

    if you need a global function to do

    isset($var) ? $var : 'default'

    the best place to define them is in you application bootstrap.
  • What properties of the object are you trying to get wheefuel?
  • Oh, just stuff like an error message for example.

    So I will write a small helper and put it inside fuel/app/bootstrap.php. I just wondered, whether I could use the existing one.

    Thank you for your help.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion