docs icon indicating copy to clipboard operation
docs copied to clipboard

Allow to use class name constants when loading table classes

Open bancer opened this issue 7 months ago • 1 comments

Description

At the present time you should use a magic string to load a table class: $articles = $this->getTableLocator()->fetchTable('Articles');.

It would be better to use a constant IMHO: $articles = $this->getTableLocator()->fetchTable(ArticlesTable::class); and to extract the alias from the class name inside fetchTable method. In case when an alias does not follow the naming conventions it should be possible to set it by using the options parameter: $articles = $this->getTableLocator()->fetchTable(ArticlesTable::class, ['alias' => 'MyArticle']);

CakePHP Version

No response

bancer avatar Apr 24 '25 08:04 bancer

It looks like this has already been implemented but documented neither in method doc blocks nor in the cookbook.

https://github.com/cakephp/cakephp/blob/e8fbbd7f668b30e98293813db600258fadead5a6/tests/TestCase/ORM/Locator/LocatorAwareTraitTest.php#L79

bancer avatar Apr 24 '25 08:04 bancer

Do you want to make a PR to add a note to the docs?

dereuromark avatar Jul 18 '25 15:07 dereuromark

This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Nov 16 '25 00:11 github-actions[bot]