2011-11-08 49 views
3

我的印象是我們必須聲明 - public $ name ='ModelName';在PHP4專用模型中。現在CakePHP不再支持PHP4了,我認爲不再需要在模型中使用$ name聲明。食譜仍然有指示,以包括它雖然:http://book.cakephp.org/2.0/en/models.html

模型工作正常,沒有它從我看到的。它用於什麼,爲什麼我需要它?

謝謝!

+1

N. B.你也不需要定義,如果你正在運行PHP'型號:: name'在CakePHP的1.3 5+。 – deizel

回答

0

你不需要任何類中的$ 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); 
} 
相關問題