# |
Jul 21st 2017, 14:51 |
bernat |
Hi. Is this answer the correct one? https://stackoverflow.com/questions/32969433/cakephp-3-save-extra-data-in-join-table |
# |
Jul 21st 2017, 14:51 |
neon1024 |
Great time to learn! |
# |
Jul 21st 2017, 14:51 |
jeremyharris |
we can help with that mirec :slightly_smiling_face: |
# |
Jul 21st 2017, 14:50 |
mirec |
guys, can I make some new feature to cakephp (migrations plugin) without writing tests? is there somebody who could write tests after I make pull request? cause I do not know how to do it properly :)) |
# |
Jul 21st 2017, 14:50 |
jeremyharris |
ok so you are using the magic arguments, not $event->getData |
# |
Jul 21st 2017, 14:50 |
birdy247 |
i.e. $start |
# |
Jul 21st 2017, 14:50 |
birdy247 |
instead its the optional data I send it |
# |
Jul 21st 2017, 14:49 |
birdy247 |
i.e. an instance of the subject with access to its properties |
# |
Jul 21st 2017, 14:49 |
birdy247 |
in the listener, the 2nd param is not what I expect |
# |
Jul 21st 2017, 14:49 |
jeremyharris |
I’m confused - what’s the problem birdy? |
# |
Jul 21st 2017, 14:48 |
birdy247 |
it is* |
# |
Jul 21st 2017, 14:48 |
birdy247 |
I thought it would be It is |
# |
Jul 21st 2017, 14:48 |
neon1024 |
@birdy247 Shouldn’t the second param be `$this` which would be an instance of the table class, assuming your event name |
# |
Jul 21st 2017, 14:38 |
devito |
thanks guys |
# |
Jul 21st 2017, 14:38 |
devito |
nice. ill check out the security component for this |
# |
Jul 21st 2017, 14:38 |
birdy247 |
in my listener, the 2nd argument is the value of start |
# |
Jul 21st 2017, 14:37 |
birdy247 |
I am dispatching that from my SettingsTable |
# |
Jul 21st 2017, 14:37 |
jeremyharris |
if the field is hidden, the security component will protect it from being tampered with |
# |
Jul 21st 2017, 14:37 |
birdy247 |
$event = new Event('Model.Settings.afterStart', $this, [ 'start' => $start ]); |
# |
Jul 21st 2017, 14:37 |
jay |
Or use SESSION |
# |
Jul 21st 2017, 14:37 |
jay |
Hidden values you can maintain with a hash |
# |
Jul 21st 2017, 14:36 |
mirec |
yep, set it manually or you can validate it |
# |
Jul 21st 2017, 14:36 |
mikesmoniker |
The Security component can prevent people from messing with which fields are submitted but I don’t think it works on values. You’d probably need to just manually set model in your action or use a model event to set it based on something. |
# |
Jul 21st 2017, 14:35 |
devito |
i think i read somethign about it in the cookbook but dont recall off the top of my head |
# |
Jul 21st 2017, 14:34 |
devito |
is there a way to prevent form tampering? I want to explictly set the model name in my forms and dont want a user inspecting and changing it on me |
# |
Jul 21st 2017, 14:33 |
devito |
yea that would be a bad thing to forget hehe |
# |
Jul 21st 2017, 14:33 |
devito |
mm |
# |
Jul 21st 2017, 14:33 |
mirec |
do not forget two column index on (model, foreign_key) in your images table |
# |
Jul 21st 2017, 14:32 |
devito |
yea |
# |
Jul 21st 2017, 14:32 |
mirec |
yep I see... so Posts->hasMany('Images', ['conditions' => ['model' => 'Posts'], 'foreignKey' => 'foreign_key']) |
# |
Jul 21st 2017, 14:31 |
devito |
a post can have many images |
# |
Jul 21st 2017, 14:31 |
devito |
yea im tinkering with the assoiation configs now |
# |
Jul 21st 2017, 14:31 |
mirec |
why do you have foreign_key in images table? why not Posts.image_id ? |
# |
Jul 21st 2017, 14:30 |
devito |
I would just simply need to update the model column to point to the correc tmodel |
# |
Jul 21st 2017, 14:30 |
devito |
smae for $this->Page->Image->path using the same table but without traditional foreign keys. Because if i make a new content type i dont want to have to add a new column to the db to accomidate it |
# |
Jul 21st 2017, 14:29 |
mirec |
have you tried associations "conditions" config? |
# |
Jul 21st 2017, 14:28 |
devito |
i want to be able to do $this->Post->iamge |
# |
Jul 21st 2017, 14:26 |
mirec |
so you want something like $image->owner to be Post or Page ? |
# |
Jul 21st 2017, 14:26 |
mikesmoniker |
@devito Something like https://github.com/robotusers/cakephp-table-inheritance might be a starting point. |
# |
Jul 21st 2017, 14:26 |
devito |
setting to be saved that is... |
# |
Jul 21st 2017, 14:25 |
devito |
my biggest concern with this approach is setting the entity data correctly. |