# |
Jun 26th 2019, 22:07 |
cnizzardini |
would be nice if I could define something as a collection of App\Model\Enity\Person |
# |
Jun 26th 2019, 22:06 |
cnizzardini |
not really |
# |
Jun 26th 2019, 22:04 |
mdotobie |
I’m thinking that’s what you’re going for @cnizzardini |
# |
Jun 26th 2019, 22:00 |
mdotobie |
if it encounters an object that doesn’t belong to that class in the array it will return false and fail |
# |
Jun 26th 2019, 21:58 |
mdotobie |
and then do something like `$isObjectCollection = $collection->every(function ($object) { return $object instanceof someClass; }); |
# |
Jun 26th 2019, 21:57 |
mdotobie |
You could then say `$collection = new Cake\Collection\Collection($objects); |
# |
Jun 26th 2019, 21:56 |
slackebot |
<mdotobie> |
# |
Jun 26th 2019, 21:54 |
mdotobie |
so lets say you had something like: |
# |
Jun 26th 2019, 21:53 |
mdotobie |
well you’d write a closure for something like Collection::every() |
# |
Jun 26th 2019, 21:53 |
cnizzardini |
like does it complain if I chuck in something goofy? |
# |
Jun 26th 2019, 21:52 |
mdotobie |
You’d need to make the base array into a collection first |
# |
Jun 26th 2019, 21:52 |
cnizzardini |
Does that just happen magically |
# |
Jun 26th 2019, 21:52 |
mdotobie |
you could use it for that. |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
*collection of instances, you know what i mean |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
But I want to verify that array is a collect of a specific class |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
My use-case is I want to pass an array of objects as an argument |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
Maybe its not what I need |
# |
Jun 26th 2019, 21:51 |
cnizzardini |
Hmmm |
# |
Jun 26th 2019, 21:51 |
mdotobie |
Some things automatically inherit from it, like `ResultsSet` |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
*who |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
why would have thought! |
# |
Jun 26th 2019, 21:50 |
mdotobie |
Yep @cnizzardini, it’s called Collections as well. |
# |
Jun 26th 2019, 21:50 |
cnizzardini |
Does cake have anything like laravels collections? |
# |
Jun 26th 2019, 21:30 |
mdotobie |
When a new Modelless Form is instantiated, I can’t for the life of me figure out how the `schema()` method is getting called. I can override the `_buildSchema()` method in the subclass, but I can’t see where `schema()` is getting called in the first place in order to get to the `_buildSchema()` method. It isn’t in the constructor. |
# |
Jun 26th 2019, 19:43 |
mdotobie |
I’ve reasoned that I can additionally create a new `ContextInterface` that I will call `GraphContext` that will be used by the `FormHelper` class to utilize the custom properties on each field in the `GraphSchema` |
# |
Jun 26th 2019, 19:41 |
mdotobie |
So @admad, I’ve spent the last few hours on the problem I was starting to discuss earlier and my first step towards a solution has been to write a subclassed version of the `Cake\Form\Schema` class. I’m calling it a `GraphSchema`. This way I can define custom properties for each field through the `addField()` method in addition to the `type`, `length`, `precision` and `default` fields setup by the parent `Schema` class. |
# |
Jun 26th 2019, 16:33 |
michal.ferak |
that works! thank you for your help @admad |
# |
Jun 26th 2019, 16:33 |
michal.ferak |
thanks, I think perhaps like this: $this->response = $this->response->withStatus(400); |
# |
Jun 26th 2019, 16:32 |
admad |
`$this->response = $this->response->withStatuCode(400);` |
# |
Jun 26th 2019, 16:31 |
admad |
Apologies, I misread your code. I fixed the code in my previous comment too |
# |
Jun 26th 2019, 16:30 |
slackebot |
<michal.ferak> |
# |
Jun 26th 2019, 16:29 |
slackebot |
<michal.ferak> |
# |
Jun 26th 2019, 16:27 |
admad |
@michal.ferak what you claim as deprecated isn't. You jus need to change bit to `$this->response = $this->response->statusCode(400);` |
# |
Jun 26th 2019, 16:22 |
slackebot |
<michal.ferak> |
# |
Jun 26th 2019, 16:21 |
michal.ferak |
Let me rephrase. The method I posted earlier is in fact a controller method. I adjusted the original example. |
# |
Jun 26th 2019, 16:17 |
niel45 |
Can I get an invite to the slack workspace? |
# |
Jun 26th 2019, 16:17 |
michal.ferak |
Thanks. Not sure I follow what you mean. I tried modifying `$this->status` directly but that didn’t work |
# |
Jun 26th 2019, 16:13 |
admad |
You can directly use the property too |
# |
Jun 26th 2019, 16:13 |
michal.ferak |
@admad Thanks, this works - is it a correct approach? $this->setResponse($this->response->withStatus($response->getStatusCode())); |
# |
Jun 26th 2019, 16:12 |
admad |
By returning it directly you are preventing the normal rendering |
# |
Jun 26th 2019, 16:11 |
admad |
@michal.ferak nope, you can still do the same in controller, just remember to assign back the return value to $this->response |