我的印象是我们必须声明 - public $ name ='ModelName';在PHP4专用模型中。现在CakePHP不再支持PHP4了,我认为不再需要在模型中使用$ name声明。食谱仍然有指示,以包括它虽然:http://book.cakephp.org/2.0/en/models.html
模型工作正常,没有它从我看到的。它用于什么,为什么我需要它?
谢谢!
我的印象是我们必须声明 - public $ name ='ModelName';在PHP4专用模型中。现在CakePHP不再支持PHP4了,我认为不再需要在模型中使用$ name声明。食谱仍然有指示,以包括它虽然:http://book.cakephp.org/2.0/en/models.html
模型工作正常,没有它从我看到的。它用于什么,为什么我需要它?
谢谢!
它只是早期食谱中的剩余食物。例如参见http://book.cakephp.org/2.0/en/models/model-attributes.html#name,即使CakePHP 2.0不再适用于PHP4,它也会提及PHP4的兼容性。
因此,要回答您的问题:不,您不必在模型中声明$name
。
你不需要任何类中的$ name。 甚至没有1.3(仍然使用php4 ^^),但特别是不在2.0。
我写了一个增强UpgradeShell从所有类文件删除这些不必要的大块: http://cakephp.lighthouseapp.com/projects/42648/tickets/2117-improvements-for-20-upgrade-shell 但这个新的命令我没有尚未添加到售票补丁。
我叫命令 “名”
/**
* Remove name (lib, controller, model, view, component, behavior, helper, fixture)
*
* @return void
*/
public function name() {
$libs = App::path('Lib');
$views = App::path('views');
$controllers = App::path('controllers');
$components = App::path('components');
$models = App::path('models');
$helpers = App::path('helpers');
$behaviors = App::path('behaviors');
$this->_paths = array_merge($libs, $views, $controllers, $components, $models, $helpers, $behaviors);
$this->_paths[] = TESTS . 'Fixture' . DS;
if (!empty($this->params['plugin'])) {
$pluginPath = App::pluginPath($this->params['plugin']);
$this->_paths = array(
$pluginPath . 'Lib' . DS,
$pluginPath . 'Controller' . DS,
$pluginPath . 'Controller' . DS . 'Component' .DS,
$pluginPath . 'View' . DS,
$pluginPath . 'View' . DS . 'Helper' . DS,
$pluginPath . 'Model' . DS,
$pluginPath . 'Model' . DS . 'Behavior' . DS,
$pluginPath . 'Test' . DS . 'Fixture' . DS,
$pluginPath . 'libs' . DS,
$pluginPath . 'controllers' . DS,
$pluginPath . 'controllers' . DS . 'components' .DS,
$pluginPath . 'views' . DS,
$pluginPath . 'views' . DS . 'helpers' .DS,
$pluginPath . 'models' . DS,
$pluginPath . 'models' . DS . 'behaviors' . DS,
$pluginPath . 'tests' . DS . 'fixtures' . DS,
);
}
$patterns = array(
array(
'remove var $name = ...;',
'/\bvar\s*\$name\s*=\s*(.*);/',
''
),
array(
'remove public $name = ...;',
'/\bpublic\s*\$name\s*=\s*(.*);/',
''
),
);
$this->_filesRegexpUpdate($patterns);
}
N. B.你也不需要定义,如果你正在运行PHP'型号:: name'在CakePHP的1.3 5+。 – deizel