2011-01-21 4 views
1

나는 kohana 프레임 워크를 기반으로하는 gallery3 PHP 소프트웨어를 사용하고 있습니다. 아무도 앨범 정보 양식에 확인란을 추가하는 방법을 알고 있습니까?갤러리 3 소프트웨어의 Kohana 폼의 체크 박스

나는 다음과 같은 시도 :

정적 기능 get_edit_form ($ 부모) { $ 양식 = 새로운 포지 ( "앨범/업데이트/{$ 학부모> ID}", "", "POST", array ("id"=> "g-edit-album-form")); $ form-> hidden ("from_id") -> 값 ($ parent-> id); $ group = $ form-> group ("edit_item") -> label (t ("앨범 편집"));

$group->input("title")->label(t("Title"))->value($parent->title) 
    ->error_messages("required", t("You must provide a title")) 
    ->error_messages("length", t("Your title is too long")); 
$group->textarea("description")->label(t("Description"))->value($parent->description); 
/* MPK: information fields for albums */ 
$group->textarea("information")->label(t("Information text"))->value($parent->information); 
$group->checkbox("info")->label(t("Informational"))->value($parent->info); 
if ($parent->id != 1) { 
    $group->input("name")->label(t("Directory Name"))->value($parent->name) 
    ->error_messages("conflict", t("There is already a movie, photo or album with this name")) 
    ->error_messages("no_slashes", t("The directory name can't contain a \"/\"")) 
    ->error_messages("no_trailing_period", t("The directory name can't end in \".\"")) 
    ->error_messages("required", t("You must provide a directory name")) 
    ->error_messages("length", t("Your directory name is too long")); 
    $group->input("slug")->label(t("Internet Address"))->value($parent->slug) 
    ->error_messages(
     "conflict", t("There is already a movie, photo or album with this internet address")) 
    ->error_messages(
     "not_url_safe", 
     t("The internet address should contain only letters, numbers, hyphens and underscores")) 
    ->error_messages("required", t("You must provide an internet address")) 
    ->error_messages("length", t("Your internet address is too long")); 
} else { 
    $group->hidden("name")->value($parent->name); 
    $group->hidden("slug")->value($parent->slug); 
} 

공공 기능 업데이트 ($ album_id) { 액세스 :: verify_csrf(); $ album = ORM :: factory ("item", $ album_id); access :: required ("view", $ album); access :: required ("edit", $ album);

$form = album::get_edit_form($album); 
try { 
    $valid = $form->validate(); 
    $album->title = $form->edit_item->title->value; 
    $album->description = $form->edit_item->description->value; 
    /* MPK: information fields for albums */ 
    $album->information = $form->edit_item->information->value; 
    $album->info = $form->edit_item->info->value; 
    $album->sort_column = $form->edit_item->sort_order->column->value; 
    $album->sort_order = $form->edit_item->sort_order->direction->value; 
    if (array_key_exists("name", $form->edit_item->inputs)) { 
    $album->name = $form->edit_item->inputs["name"]->value; 
    } 
    $album->slug = $form->edit_item->slug->value; 
    $album->validate(); 
} catch (ORM_Validation_Exception $e) { 
    // Translate ORM validation errors into form error messages 
    foreach ($e->validation->errors() as $key => $error) { 
    $form->edit_item->inputs[$key]->add_error($error, 1); 
    } 
    $valid = false; 
} 

if ($valid) { 
    $album->save(); 
    module::event("item_edit_form_completed", $album, $form); 

    log::success("content", "Updated album", "<a href=\"albums/$album->id\">view</a>"); 
    message::success(t("Saved album %album_title", 
        array("album_title" => html::purify($album->title)))); 

    if ($form->from_id->value == $album->id) { 
    // Use the new url; it might have changed. 
    json::reply(array("result" => "success", "location" => $album->url())); 
    } else { 
    // Stay on the same page 
    json::reply(array("result" => "success")); 
    } 
} else { 
    json::reply(array("result" => "error", "html" => (string)$form)); 
} 

}

필드는 양식에 표시 않지만, 필드 값은 DB에 저장되지 않습니다. DB에서는 tinyint (1)입니다.

+0

질문의 시작 부분에 코드 서식을 수정해야 할 수 있습니다. – Donovan

답변

0

Kohana는 모델을 사용하여 데이터베이스에 데이터를 저장합니다. $album->save();으로 인해 Kohana 버전에 따라 응용 프로그램의 어딘가에 모델이 있어야합니다.

/modules/gallery/models으로 이동하십시오. item.php이라는 파일이 있습니다. 이것은 항목 (및 앨범)을 저장 /로드/생성하기 위해 응용 프로그램에서 사용하는 모델입니다. 447 번째 줄에는 실제로 데이터베이스의 내용을 데이터베이스에 저장하는 명령이 있습니다. 체크 박스의 값을 저장하려면 해당 행을 변경해야합니다.

+0

갤러리 3 최신 버전을 사용하고 있습니다. item.php에는 필드 이름이 언급되어 있지 않습니다. 필드 목록을 실행하고 저장하는 절차가 있습니다. 필드 이름은 컨트롤러 albums.php에 언급되어 있습니다. 나는 그것에 자신의 필드를 추가했습니다. 다른 모든 필드는 잘 저장되며 저장되지 않는 체크 상자 값입니다. – Marek

0

해결되었습니다. 문제는 할당의 값 필드가 아닌 확인란의 '확인'필드를 사용해야한다는 것입니다. albums.php에서 album.php  

$group->checkbox("info")->label(t("Informational"))->value($parent->info)->checked($parent->info); 

에서

은 :

$album->info = $form->edit_item->info->checked; 

DB를의 필드는 '정보'라는 이름과 비트가 될 수 있습니다.