CakePHP Model Name Uses PHP Reserved Word

Hey, I encoded CakePHP for a number of things, but I never came across this problem before, surprisingly. In addition, I carefully checked the files on the network and CakePHP and did not find the answer to my question. My question is that I have a table for my model, which should be called a class, obviously I cannot use this name, though, since this is a reserved PHP keyword. What options should I have in order to be able to access this model accordingly.

So far, I:

  • Renamed the class model file to player_class.php
  • Renamed the class class class to PlayerClass
  • Var $ name changed to 'PlayerClass'
  • Added to class model class; var $ useTable = 'classes';
  • Renamed my class controller to player_classes_controller.php
  • Renamed the class class class to PlayerClassesController
  • Var variable name changed to 'PlayerClasses'

While this works, this is something that needs to be done or to other parameters in order to be able to refer to it as a class yet, how can I do some kind of manipulation like _Class?

+4
source share
3 answers

When I encounter such a problem, I usually do what you did, only I prefix the reserved word with "My" (therefore, when I read the code, it does not look like this class has anything to do with "Player "" ... for example, the other day I wanted to simulate the "ACO" model .. but it already existed in the cake (the same script of the reserved word), so I created a model called Myaco.

I think you should just call it Myclass.

As for the model name and controller name, I think you did good, I would do the same. Your only real option is to use $useTable = 'classed'; to use your db table.

If you use the underscore prefix, I believe the cupcake will not be able to handle it (it will fail in the Inflector class).

Good luck.

+3
source

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

NOT possible:

 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 

Maybe:

 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 
+4
source

I can repeat this decision. I had the same problem and used the prefix that was the initial of the client. The call to my Dtclass has ended. Unfortunately, it took me an hour or so to figure out what the problem was. One of those cases when the answer constantly looks at you in the face until you finally recognize it.

+1
source

All Articles