Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Default parameters in ViewModels
  • I would like to set default parameters values to into ViewModels and I don't know what is the best way to do it.

    The idea is to define, in a very simple way, default view parameters values into the viewmodel, and update those values only if needed in the controller, so that the view don't hang if a param is not set without having to spend time to check them.

    Actually, the only way I see is to test if the param is defined (from the controller) in the view method, and set it to default value if not.
  • HarroHarro
    Accepted Answer
    The challenge is that the Viewmodel itself doesn't have a data container, it uses the associated View object to store variables. So you can't set values until you have a View assigned.

    You could overload the Viewmodel class, add something that will define these defaults, and that sets these defaults on the View object when created or passed to the Viewmodel instance.
  • Thanks ! That's what I'm about to do.

Howdy, Stranger!

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

In this Discussion