本文整理汇总了PHP中product::get_add_form_admin方法的典型用法代码示例。如果您正苦于以下问题:PHP product::get_add_form_admin方法的具体用法?PHP product::get_add_form_admin怎么用?PHP product::get_add_form_admin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类product
的用法示例。
在下文中一共展示了product::get_add_form_admin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_product
public function add_product()
{
access::verify_csrf();
$form = product::get_add_form_admin();
try {
$valid = $form->validate();
$product = ORM::factory("product");
$product->name = $form->add_product->inputs["name"]->value;
$product->description = $form->add_product->description->value;
$product->postage_band_id = $form->add_product->postage_band->value;
$product->validate();
} catch (ORM_Validation_Exception $e) {
// Translate ORM validation errors into form error messages
foreach ($e->validation->errors() as $key => $error) {
$form->add_product->inputs[$key]->add_error($error, 1);
}
$valid = false;
}
if ($valid) {
$product->save();
message::success(t("Created product %product_name", array("product_name" => html::clean($product->name))));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error", "form" => (string) $form));
}
}
示例2: add_product
public function add_product()
{
access::verify_csrf();
$form = product::get_add_form_admin();
$valid = $form->validate();
$name = $form->add_product->inputs["name"]->value;
$product = ORM::factory("product")->where("name", "=", $name)->find();
if ($product->loaded()) {
$form->add_product->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
if ($valid) {
$product = product::create($name, $form->add_product->cost->value, $form->add_product->description->value, $form->add_product->postage_band->value);
$product->save();
message::success(t("Created product %product_name", array("product_name" => html::clean($product->name))));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error", "form" => $form->__toString()));
}
}