Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Model Name Uses PHP Reserved Word

Hey I have coded CakePHP for a number of things but never ran into this problem before surprisingly. Also I have thoroughly searched the net and CakePHP docs and have not found an answer to my question. My question is, I have a table for my model that should be named Class, obviously I cannot use that name though since it's a reserved PHP keyword. What options do I have to be able to refer to this model appropriately.

So far I have;

  1. Renamed my class model file to player_class.php
  2. Renamed my class model class to PlayerClass
  3. Changed var $name to 'PlayerClass'
  4. Added to my class model class; var $useTable = 'classes';
  5. Renamed my class controller to player_classes_controller.php
  6. Renamed my class controller class to PlayerClassesController
  7. Changed var $name to 'PlayerClasses'

While this does work, is this what has to be done or are to other options to be able to refer to it as Class still, like can I do any sort of mangling like _Class?

like image 235
Axpen Avatar asked Jan 23 '23 21:01

Axpen


1 Answers

I once tested all CakePHP class names for Cake 1.2 if they can be used as Model names, here are the results:

NOT possible is:

app
appcontroller
appmodel
behaviorcollection
cache
cacheengine
cakelog
cakesession
classregistry
component
configure
connectionmanager
controller
datasource
debugger
dispatcher
file
fileengine
folder
helper
inflector
model
modelbehavior
object
overloadable
overloadable2
router
security
sessioncomponent
set
string
validation

Possible is:

acl
aclbase
aclbehavior
aclcomponent
aclnode
aclshell
aco
acoaction
admin
ajaxhelper
apcengine
apishell
app_model
apphelper
aro
authcomponent
bake
baker
bakeshell
behavior
cachehelper
cake
cakeschema
cakesocket
consoleshell
containablebehavior
controllertask
cookiecomponent
dbacl
dbaclschema
dbconfigtask
dboadodb
dbodb2
dbofirebird
dbomssql
dbomysql
dbomysqlbase
dbomysqli
dboodbc
dbooracle
dbopostgres
dbosource
dbosqlite
dbosybase
element
emailcomponent
error
errorhandler
extracttask
flay
formhelper
htmlhelper
httpsocket
i18n
i18nmodel
i18nschema
i18nshell
iniacl
javascripthelper
jshelper
jshelperobject
l10n
layout
magicdb
magicfileresource
mediaview
memcacheengine
modeltask
multibyte
numberhelper
page
pagescontroller
paginatorhelper
permission
plugintask
projecttask
requesthandlercomponent
rsshelper
sanitize
scaffold
schema
schemashell
securitycomponent
sessionhelper
sessionsschema
shell
shelldispatcher
test
testsuiteshell
testtask
texthelper
themeview
timehelper
translate
translatebehavior
treebehavior
viewtask
xcacheengine
xml
xmlelement
xmlhelper
xmlmanager
xmlnode
xmltextnode
like image 155
powtac Avatar answered Jan 30 '23 11:01

powtac