# |
Oct 11th 2019, 02:16 |
Fastidius |
hi all, as some of you know i am slowly getting my head around cakephp by playing with UI changes to make life better for users. |
# |
Oct 10th 2019, 19:22 |
ricksaccous |
best way imo |
# |
Oct 10th 2019, 19:22 |
risingtide |
So would I put it in my Posts model then? |
# |
Oct 10th 2019, 19:13 |
ricksaccous |
would be the "cleaner" way |
# |
Oct 10th 2019, 19:13 |
ricksaccous |
and just call that in your controller and be done with it |
# |
Oct 10th 2019, 19:13 |
ricksaccous |
$this->Posts->getLatestPost(int $projectId); |
# |
Oct 10th 2019, 19:13 |
ricksaccous |
if you just had it as a model method though you could just say |
# |
Oct 10th 2019, 19:13 |
ricksaccous |
int he controller you'd feed it the option, then you'd have latest_post available in the veiw |
# |
Oct 10th 2019, 19:12 |
ricksaccous |
in the entity it would be findandsetlatestpost |
# |
Oct 10th 2019, 19:12 |
ricksaccous |
well i was using your entity example |
# |
Oct 10th 2019, 19:10 |
risingtide |
sounds like I have to rewrite a lot |
# |
Oct 10th 2019, 19:10 |
risingtide |
I'm still confused |
# |
Oct 10th 2019, 19:10 |
risingtide |
and in the controller I'd set it as a feild? |
# |
Oct 10th 2019, 19:09 |
risingtide |
So in my Model I'd make the findAndSetLatestPost function |
# |
Oct 10th 2019, 19:04 |
ricksaccous |
you could always just grab it as a separate query given the project id/etc |
# |
Oct 10th 2019, 19:04 |
ricksaccous |
sounds more like business layer logic though |
# |
Oct 10th 2019, 19:01 |
ricksaccous |
you'd have to do some set up |
# |
Oct 10th 2019, 19:01 |
ricksaccous |
if you need to pass something in i don't see how you can just have it "available" |
# |
Oct 10th 2019, 19:01 |
ricksaccous |
or whatever |
# |
Oct 10th 2019, 19:01 |
ricksaccous |
$entity->findAndSetLatestPost($projectEntity->id); |
# |
Oct 10th 2019, 19:00 |
ricksaccous |
in your controller |
# |
Oct 10th 2019, 19:00 |
ricksaccous |
public function findAndSetLatestPost(int $somethingId) { $this->property = value} |
# |
Oct 10th 2019, 19:00 |
risingtide |
how would I do it in the controller? |
# |
Oct 10th 2019, 18:59 |
ricksaccous |
if you really need it in the entity you can have an arbitrary function that sets a field given an argument |
# |
Oct 10th 2019, 18:59 |
ricksaccous |
it would make sense to do it in the controller |
# |
Oct 10th 2019, 18:58 |
ricksaccous |
or where do you want to pass the argument |
# |
Oct 10th 2019, 18:58 |
ricksaccous |
the view? |
# |
Oct 10th 2019, 18:58 |
ricksaccous |
where are you passing the argument in anyway |
# |
Oct 10th 2019, 18:58 |
ricksaccous |
contain the posts and order it, i suppose limiting it by 1 won't have an effect |
# |
Oct 10th 2019, 18:57 |
ricksaccous |
can't you do this in the controller/model level |
# |
Oct 10th 2019, 18:57 |
risingtide |
yes |
# |
Oct 10th 2019, 18:57 |
risingtide |
so forums have multiple projects |
# |
Oct 10th 2019, 18:57 |
ricksaccous |
so projects habtm forums |
# |
Oct 10th 2019, 18:56 |
risingtide |
but each project has its own forum, but many projects can have the same forum |
# |
Oct 10th 2019, 18:56 |
ricksaccous |
oh, so i suppose you could if you did it from projects, lol |
# |
Oct 10th 2019, 18:56 |
risingtide |
it's a basic forum model |
# |
Oct 10th 2019, 18:56 |
risingtide |
and threads |
# |
Oct 10th 2019, 18:56 |
risingtide |
projects have many forums which have many posts |
# |
Oct 10th 2019, 18:56 |
risingtide |
no, not really |
# |
Oct 10th 2019, 18:55 |
ricksaccous |
is that something you can do? |
# |
Oct 10th 2019, 18:55 |
ricksaccous |
and then have the entity read that field? |