Welcome Guest, Not a member yet? Register   Sign In
Help on entities
#4

(This post was last modified: 06-25-2020, 10:21 PM by Leo.)

(06-25-2020, 03:14 PM)vinezof2 Wrote: $allowedFields is really necessary? i don't got it very well because all attributes where in the entity and this makes me confused
No, you can set this in your models $protectFields = false;
But, I usually fill them out because regardless if you write entity fields or not, $allowedFields is the one that handles "filtering" of data. Basically if you do this: $product->fill($_POST) - you may get stuff you don't need in there and with $allowedFields it cross-references what is "valid" and what gets left out.

Theres one example on entities I would like to see though.
How to handle business logic of a bunch of fields.
Currenty I do this: $product->fill($input) with $input variable holding an array of processed data I handled elsewhere in my controller.

I know I can do business logic in entities though, which would clean up my code somewhat, but I'm not sure how to go about this.
I want to actually do this: $product->fill($_POST)
And within entities I want to check each $_POST value - if it is '' set it to null, if it has a trailing space in the beginning or end i want to trim() (users tend to press the spacebar inadvertently). And for one of the $_POST fields - the url I want to do this: url_title($_POST['posted_url'])
Anyone got a good example on this?
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply


Messages In This Thread
Help on entities - by MatheusCastro - 06-24-2020, 05:37 AM
RE: Help on entities - by Leo - 06-25-2020, 02:41 PM
RE: Help on entities - by vinezof2 - 06-25-2020, 03:14 PM
RE: Help on entities - by Leo - 06-25-2020, 10:04 PM
RE: Help on entities - by vinezof2 - 06-26-2020, 04:25 AM
RE: Help on entities - by Leo - 06-26-2020, 07:02 AM
RE: Help on entities - by vinezof2 - 06-26-2020, 10:24 AM
RE: Help on entities - by Leo - 06-26-2020, 01:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB