2011-08-31 2 views
2

양식 유효성 검사 오류를 번역 할 모델이 있습니다.생성자가있는 모델에서 멤버 함수 trigger()를 호출합니다.

나는 다음과 같은 오류가 어떤 페이지를 열 때마다
function __construct() { 
    $this->validate = array(
     'url' => array(
      'url' => array(
       'rule' => array('url'), 
       'message' => __('Enter a valid URL', true), 
      ), 
     ), 
     'revisit' => array(
      'numeric' => array(
       'rule' => array('numeric'), 
       'allowEmpty' => true, 
      ), 
     ), 
     'reading_list' => array(
      'boolean' => array(
       'rule' => array('boolean'), 
      ), 
     ), 
    ); 
} 

이 : 내가 거기에 __() 기능을 사용하기 전에

Fatal error: Call to a member function trigger() on a non-object in /home/mu/Branches/cakemarks/cake/libs/model/model.php on line 2106 

Call Stack: 
    0.0005  347980 1. {main}() /home/mu/Branches/cakemarks/app/webroot/index.php:0 
    0.0548 3580716 2. Dispatcher->dispatch() /home/mu/Branches/cakemarks/app/webroot/index.php:83 
    0.0597 3735300 3. Dispatcher->_invoke() /home/mu/Branches/cakemarks/cake/dispatcher.php:171 
    0.1451 7428100 4. call_user_func_array() /home/mu/Branches/cakemarks/cake/dispatcher.php:204 
    0.1451 7428336 5. BookmarksController->startscreen() /home/mu/Branches/cakemarks/cake/dispatcher.php:0 
    0.1451 7429132 6. Model->find() /home/mu/Branches/cakemarks/app/controllers/bookmarks_controller.php:100 

, 내가있을 수 있었다 그래서 생성자에 $validate의 충만을 이동 $validate은 야외에서 잘 작동했습니다.

여기 유효성 검사 메시지를 어떻게 만들 수 있습니까? the manual recommends, 또한

public function __construct($id = false, $table = null, $ds = null) { 
    // do your thing 

    parent::__construct($id, $table, $ds); 
} 

:

답변

3

생성자가 괜찮 재정의,하지만 당신은 할 필요가 있는지 원래의 생성자는 실행

If you would like to have all of your validation error messages translated by default, a simple solution would be to add the following code in you app_model.php :

function invalidate($field, $value = true) { 
    return parent::invalidate($field, __($value, true)); 
}