duannaikuang1301 2011-01-21 17:08
浏览 24

在gallery3软件中的Kohana表格上的复选框

I am using gallery3 php software, which is based on the kohana framework. Does anybody know how to add a checkbox to the album information form?

I tried like this:

static function get_edit_form($parent) { $form = new Forge( "albums/update/{$parent->id}", "", "post", array("id" => "g-edit-album-form")); $form->hidden("from_id")->value($parent->id); $group = $form->group("edit_item")->label(t("Edit Album"));

$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);
}

AND

public function update($album_id) { access::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));
}

}

The field does show up on the form, but the field value does not get saved to the DB. In the DB it is a tinyint(1).

  • 写回答

2条回答 默认 最新

  • duanjiao8007 2011-01-21 17:38
    关注

    Kohana uses models to save data in the database. Because of $album->save(); you should have a model somewhere in the application, depending of the version of Kohana.

    Go to /modules/gallery/models. There is a file called item.php. This is the model used by the application to save/load/create items (and also albums). At line 447 there is the command which actually saves the contents of the album in the database. You need to change that line in order to save the value of the checkbox.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?