2011-11-08 2 views
3

우리는 선언해야한다는 인상하에있었습니다. public $ name = 'ModelName'; PHP4 전용 모델. 이제 cakephp가 더 이상 PHP4를 지원하지 않아서 모델에서 $ name 선언이 더 이상 필요 없다고 생각했습니다. 요리 책에는 아직도 그것을 포함하는 지시가있다 : http://book.cakephp.org/2.0/en/models.html

내가 본 것에서 그것없이 모델은 잘 동작한다. 그게 무슨 용도로 쓰이고, 왜 내가 그것을 필요로합니까?

감사합니다.

+1

N.의 B를했다. – deizel

답변

0

당신은 어떤 수업에서도 $ name이 필요하지 않습니다. 1.3에서도 (여전히 어쨌든 php4를 사용하는 사람 ^^), 특히 2.0에서는 그렇지 않습니다.

나는 모든 클래스 파일에서 이러한 불필요한 덩어리를 제거하는 강화 된 UpgradeShell 썼다 : http://cakephp.lighthouseapp.com/projects/42648/tickets/2117-improvements-for-20-upgrade-shell 을하지만이 새로운 명령은 아직 티켓 패치에 추가 didnt한다.

나는 명령 "이름"당신은 또한 CakePHP의 1.3 '모델 :: name` 당신이 PHP를 실행하는 경우를 5+ 정의 할 필요가 없습니다

/** 
* 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); 
} 
관련 문제