Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how not to save property
  • Hi! 

    I have an orm\model to represent messages in a contact form. I have an email confirmation field in my model, and ofc don't want to write it in the table related. But I can't found how to do that in docs or on this forum. Sorry if the question is so nooby. 


    (I managed to did it just by changing a bit the orm\Model save() method, but I want to know if there is a native mechanism to do this). 


  • The properties of an ORM model MUST match the columns in the table. You can't leave any out, and you can't invent new ones.

    So instead of doing something you're not supposed to, and then hack your way around it, start by telling us why you need that field there?
  • I put that email_conf field in the $_properties of my model since I want it to display on the form.

    But, from your answer, obviously that isnt the proper way to handle that... should I add the email_conf  from field outside the $_properties of the model?
  • HarroHarro
    Accepted Answer
    I assume you use a fieldset, and use add_model() to generate the fieldset?

    If that is so, you can add a method to your model called set_form_fields(). It is called by add_model(), It's prototype is:

    void public static function set_form_fields($fieldset, $instance = null) {}

    it gets passed the fieldset object you are creating, and optionally a model instance in case you call add_model() with an instance instead of a model name.

    in your method, call

    parent::set_form_fields($fieldset, $instance)

    first, to create the fieldset from the model. After that, you can modify the fieldset. You can also use this to populate the fieldset with for example dropdown values (option arrays), custom labels, etc.
  • Thanks!  That seems great. 


  • Good luck. Any more questions, just shout! ;-)

Howdy, Stranger!

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

In this Discussion