다음은 현재 코드의 대략적인 형태입니다. CodeIgniter의 1.7 사용하여 문제의 본질에 아래로 손질 : system/application/controllers/some_controller.php
에서CodeIgniter에서 폼 유효성 검사 커스텀 콜백 메소드를위한 라벨에 여러 문자열 보간을 적용 할 수 있습니까?
'some_controller/save' => array(
array(
'field' => 'some_code',
'label' => 'Some Code Name',
'rules' => 'trim|required|min_length[1]|max_length[6]|callback__unique_codename'
),
),
, 나는 위의 검증에 필요한 사용자 정의 콜백 기능을 가지고 : system/application/config/form_validation.php
에서
을, 나는 다음과 같은 규칙이 규칙 :
function _unique_codename($codename)
{
$result = $this->some_code_model->find_by_codename($codename); // this returns NULL if the codename is not found
if ($result)
{
$this->form_validation->set_message('_unique_codename', '%s already exists. Please enter another %s.');
return FALSE;
}
else
{
return TRUE;
}
}
양식 제출 후 오류가 발생합니다. 표시되는 오류는 다음과 같습니다. "일부 코드 이름이 이미 있습니다. 다른 코드 이름을 입력하십시오."
오류 메시지에서 복수 %
인스턴스를 평가할 수있는 방법이 있습니까?
나는 예제를 훨씬 단순화시킨 것 같다. 비정상적인 경우는 다음을 포함합니다 : 다른 필드에 대해 동일한 사용자 지정 콜백 함수를 사용하는 것 * 다음과 같이 사용자 지정 콜백 함수에 추가 매개 변수를 전달하는 경우 :''rules '=>'trim | required | callback__unique_codename [some_other_field] '' –