2016-10-25 2 views
1

내 prestashop 모듈이 일부 오류 메시지를 반환하고이 오류를 해결하는 방법에 대해 더 많은 질문이 있습니다.이 오류에 대한 팁을 추가하고 싶습니다. 데이터베이스에 삽입 신제품이 코드 라인 반환 오류 메세지를 지정하지 않고 예를 들어prestashop 오류 메시지에 대한 팁 추가

`$lang_field_error = $productObj->validateFieldsLang(self::UNFRIENDLY_ERROR, true)` 

"이름이 비어"나는이

$error_tmp = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); 
       if ($error_tmp != '') { 
        $this->error_msg[] = sprintf(
         Tools::displayError('Product (ID: %1$s) cannot be saved. %2$s'), 
         (isset($product['id_product']) && !empty($product['id_product'])) ? Tools::safeOutput(
          $product['id_product'] 
         ) : 'No ID', 
         $error_tmp 
        ); 
       } 
같은 errror의 MSG의 모습을 보여줄 때

$ productObj-> validateFieldsLang()이 메소드는 ObjectModel 클래스에서 가져옴

public function validateFieldsLang($die = true, $error_return = false) 
{ 
    foreach ($this->def['fields'] as $field => $data) { 
     if (empty($data['lang'])) { 
      continue; 
     } 

     $values = $this->$field; 

     // If the object has not been loaded in multilanguage, then the value is the one for the current language of the object 
     if (!is_array($values)) { 
      $values = array($this->id_lang => $values); 
     } 

     // The value for the default must always be set, so we put an empty string if it does not exists 
     if (!isset($values[Configuration::get('PS_LANG_DEFAULT')])) { 
      $values[Configuration::get('PS_LANG_DEFAULT')] = ''; 
     } 

     foreach ($values as $id_lang => $value) { 
      if (is_array($this->update_fields) && empty($this->update_fields[$field][$id_lang])) { 
       continue; 
      } 

      $message = $this->validateField($field, $value, $id_lang); 
      if ($message !== true) { 
       if ($die) { 
        throw new PrestaShopException($message); 
       } 
       return $error_return ? $message : false; 
      } 
     } 
    } 

    return true; 
} 

및 오류 MSG 인 경우, 예를 들어, 표시 을 오류 MSG를 반환 내가 종류 (

"당신이 제품의 이름은 비워 둘 수 없습니다"나는 오류를 포착해야한다 같은 오류 팁 모양을하지 추가 할 "이름 필드는 비어 있습니다" 문자열에서) 아무도 도와 줄 수 있습니까?

답변

0

파일 /classes/ObjectModel.php 파일에는 공유 한 코드에서 호출되는 validateField()라는 함수가 있습니다.

반환 된 오류를 변경하려면이 함수에 조건을 추가해야합니다. 현재 컨트롤러가 컨트롤러인지 또는 유사한 컨트롤러인지 나타내는 조건을 추가 할 수 있습니다.

Tools::getValue('controller'); 
:

당신은 현재 컨트롤러의 이름을 얻기 위해 다음과 같은 코드를 사용할 수 있습니다

관련 문제