# |
Apr 19th 2019, 11:53 |
mehov |
I thought having a noun first would kind of help when you're looking up that function in the list (so it'd all get sorted by it), but I guess that's not important |
# |
Apr 19th 2019, 11:52 |
admad |
no need for "createAccount() |
# |
Apr 19th 2019, 11:51 |
admad |
I would actually drop the noun too. Cause for eg. $this->Accounts->create() is good enough |
# |
Apr 19th 2019, 11:51 |
mehov |
Got it, thanks a lot! |
# |
Apr 19th 2019, 11:51 |
admad |
nmv, using the verb first is common practice |
# |
Apr 19th 2019, 11:50 |
admad |
in which class? |
# |
Apr 19th 2019, 11:49 |
mehov |
Hi guys, what do you think would be a better practice, naming methods `createAccount()` and `deleteAccount()` or `accountCreate()` and `accountDelete()`? Checked book.cakephp.org/3.0/en/intro/conventions.html and it says *While you can route multiple word controllers in any way you like*. Nothing on https://www.dereuromark.de/2010/10/08/complete-cakephp-naming-conventions/ either |
# |
Apr 19th 2019, 11:15 |
asdfgh |
thanks |
# |
Apr 19th 2019, 11:15 |
asdfgh |
ok |
# |
Apr 19th 2019, 11:07 |
royalty |
and then you can add caching to those, using findBy is just a quick convenience method that you should probably avoid |
# |
Apr 19th 2019, 11:07 |
royalty |
or getById(int $id) |
# |
Apr 19th 2019, 11:07 |
royalty |
getByWhatever(string $param) |
# |
Apr 19th 2019, 11:07 |
royalty |
like |
# |
Apr 19th 2019, 11:07 |
royalty |
asdfgh, it's better to define your own findBy queries |
# |
Apr 19th 2019, 11:06 |
asdfgh |
i have tried to add cache() but it is not recognized |
# |
Apr 19th 2019, 11:06 |
asdfgh |
ricks it seems that we cannot use cache() for findBy... queries |
# |
Apr 19th 2019, 11:05 |
ricksaccous |
it might work without using TableRegistry |
# |
Apr 19th 2019, 11:05 |
ricksaccous |
so if you want to try again with tableLocator |
# |
Apr 19th 2019, 11:04 |
asdfgh |
yes correct |
# |
Apr 19th 2019, 11:03 |
ricksaccous |
you'd have to do TableLocator->get(); |
# |
Apr 19th 2019, 11:03 |
ricksaccous |
the mistake you might be making is if you use TableLocator::get it won't work because the method is not static |
# |
Apr 19th 2019, 11:03 |
asdfgh |
debug(TableRegistry::getTableLocator()->get("ActivityTypes")->findByActivity('view')->first()); |
# |
Apr 19th 2019, 11:03 |
ricksaccous |
it seems that |
# |
Apr 19th 2019, 11:03 |
asdfgh |
ricks your code works! |
# |
Apr 19th 2019, 11:01 |
ricksaccous |
oh weird |
# |
Apr 19th 2019, 11:00 |
asdfgh |
thanks |
# |
Apr 19th 2019, 11:00 |
asdfgh |
ok i try |
# |
Apr 19th 2019, 11:00 |
asdfgh |
i mean tableregistry is still working but i would like to understand how to use tablelocator |
# |
Apr 19th 2019, 11:00 |
asdfgh |
we must use tablelocator |
# |
Apr 19th 2019, 11:00 |
asdfgh |
ricksaccous i read it is deprecated in 4 |
# |
Apr 19th 2019, 10:58 |
ricksaccous |
then you should be able to do $activityType->id |
# |
Apr 19th 2019, 10:57 |
ricksaccous |
$activityType = $activityTypesTable->findByActivity('view')->first(); |
# |
Apr 19th 2019, 10:57 |
ricksaccous |
so like $activityTypesTable = TableRegistry::getTableLocator->get('Activitytypes'); |
# |
Apr 19th 2019, 10:56 |
ricksaccous |
I think that you should first set the table to a variable, and isn't TableRegistry the recommended way to do that? |
# |
Apr 19th 2019, 10:47 |
asdfgh |
anyone? |
# |
Apr 19th 2019, 10:13 |
asdfgh |
and i have to get the ID of that record that has value "view" |
# |
Apr 19th 2019, 10:12 |
asdfgh |
basically i have a filed named "activity" in the activity_types table |
# |
Apr 19th 2019, 10:12 |
asdfgh |
why? |
# |
Apr 19th 2019, 10:12 |
asdfgh |
i get this error: Using $this when not in object context |
# |
Apr 19th 2019, 10:12 |
asdfgh |
$activityType = TableLocator::get('ActivityTypes')->findByActivity('view')->first(); |
# |
Apr 19th 2019, 10:12 |
asdfgh |
hello |