本文整理汇总了PHP中Model_Category::forge方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Category::forge方法的具体用法?PHP Model_Category::forge怎么用?PHP Model_Category::forge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_Category
的用法示例。
在下文中一共展示了Model_Category::forge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_Add
public function action_Add()
{
//ドロップダウンリストの生成
$select = Model_College::get_list();
if (Input::post()) {
$val = Model_Category::validate();
if ($val->run()) {
$this->form['Cid'] = Input::post('college');
$this->form['Kname'] = Input::post('Kname');
$this->form['Kkana'] = Input::post('Kkana');
$this->form['df'] = 0;
$this->form['luID'] = Auth::get_screen_name();
$college = Model_Category::forge();
$college->set($this->form);
$college->save();
Response::redirect('category');
} else {
$this->message = $val->error();
$view = View::forge('categorymanagement/CategoryAdd');
$view->set_global('message', $this->message, false);
//ドロップダウン箇所のセット
$view->set_global('select', $select, false);
}
} else {
$view = View::forge('categorymanagement/CategoryAdd');
$view->set_global('message', $this->message, false);
//ドロップダウン箇所のセット
$view->set_global('select', $select, false);
}
return $view;
}
示例2: up
public function up()
{
\DBUtil::create_table('blog_category', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true), 'name' => array('constraint' => 255, 'type' => 'varchar'), 'slug' => array('constraint' => 255, 'type' => 'varchar'), 'post_count' => array('constraint' => 11, 'type' => 'int'), 'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'));
\Model_Category::forge(array('name' => 'Category #1', 'slug' => 'category-1', 'post_count' => 3))->save();
\Model_Category::forge(array('name' => 'Category #2', 'slug' => 'category-2', 'post_count' => 1))->save();
\Model_Category::forge(array('name' => 'Category #3', 'slug' => 'category-3', 'post_count' => 0))->save();
\Model_Category::forge(array('name' => 'Category #4', 'slug' => 'category-4', 'post_count' => 0))->save();
}
示例3: action_add
public function action_add($id = null)
{
$this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
// Prepare form fieldset
$form = \Fieldset::forge('category_form', array('form_attributes' => array('class' => 'form-horizontal special')));
$form->add_model('Blog\\Model_Category');
$form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
// Get or create the post
if ($isUpdate) {
$this->data['category'] = $category = Model_Category::find($id);
$this->dataGlobal['pageTitle'] = __('backend.category.edit');
} else {
$this->data['category'] = $category = Model_Category::forge();
$this->dataGlobal['pageTitle'] = __('backend.category.add');
}
$form->populate($category);
// If POST submit
if (\Input::post('add')) {
$form->validation()->run();
if (!$form->validation()->error()) {
// Populate the category
$category->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug'), '-', true) : \Inflector::friendly_title($form->validated('name'), '-', true), 'parent_id' => $form->validated('parent_id')));
if ($category->save()) {
// Delete cache
\Cache::delete('sidebar');
// Category Post count update
foreach (Model_Category::find('all') as $category) {
$category->post_count = count($category->posts);
$category->save();
}
if ($isUpdate) {
// \Messages::success(__('backend.category.edited'));
\Session::set_flash('success', __('backend.category.edited'));
} else {
// \Messages::success(__('backend.category.added'));
\Session::set_flash('success', __('backend.category.added'));
}
\Response::redirect_back(\Router::get('admin_category'));
} else {
// \Messages::error(__('error'));
\Session::set_flash('error', __('error'));
}
} else {
// Output validation errors
foreach ($form->validation()->error() as $error) {
echo $error;
// \Messages::error($error);
\Session::set_flash('error', $error);
}
}
}
$form->repopulate();
$this->data['form'] = $form;
return \Response::forge(\View::forge('backend/category/add')->set($this->data, null, false));
}
示例4: insert
public static function insert($data)
{
try {
$props = ['code' => Model_Service_Util::gen_code(), 'parent_category_id' => !empty($data['parent_category_id']) ? $data['parent_category_id'] : 0, 'category_name' => $data['category_name'], 'rank' => Model_Category::query()->max('rank') + 1, 'level' => $data['level'], 'created_at' => date('Y-m-d H:i:s', Date::forge()->get_timestamp())];
$new = Model_Category::forge($props);
$new->save();
return $new->id;
} catch (Exception $e) {
Log::write('ERROR', $e->getMessage());
return false;
}
}
示例5: action_create
/**
* Страница создания категории
*/
public function action_create()
{
// Если форма была отправлена
if (\Input::method() == 'POST') {
$val = \Model_Category::validate('create');
if ($val->run()) {
// Создаём статью в таблице `articles`
$category = \Model_Category::forge(array('value' => \Input::post('value')));
$category->save();
\Session::set_flash('success', 'Добавлена новая категория <b>"' . $category->value . '</b>".');
\Response::redirect('admin/categories');
} else {
\Session::set_flash('error', $val->error());
}
}
$this->template->title = 'Статьи';
$this->template->content = \View::forge('categories/create');
}
示例6: action_create
public function action_create()
{
if (Input::method() == 'POST') {
$val = Model_Category::validate('create');
if ($val->run()) {
$category = Model_Category::forge(array('name' => Input::post('name'), 'keywords' => Input::post('keywords'), 'meta' => Input::post('meta')));
if ($category and $category->save()) {
Session::set_flash('success', 'Added category #' . $category->id . '.');
Response::redirect('admin/category');
} else {
Session::set_flash('error', 'Could not save category.');
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->title = "Categories";
$this->template->content = View::forge('admin/category/create');
}
示例7: action_create
public function action_create()
{
//$this->template = \View::forge('modal_login_template');
if (Input::method() == 'POST') {
$val = Model_Category::validate('create');
if ($val->run()) {
$post = Model_Category::forge(array('name' => Input::post('name')));
if ($post and $post->save()) {
Session::set_flash('success', e('Added category #' . $post->id . '.'));
Response::redirect('admin/category');
} else {
Session::set_flash('error', e('Could not save post.'));
}
} else {
Session::set_flash('error', $val->error());
}
}
$this->template->title = "Categories";
$this->template->content = View::forge('admin/category/create');
}
示例8: action_create
public function action_create()
{
\View::set_global('title', 'Add New');
if (\Input::post()) {
$val = Model_Category::validate('create');
// Upload image and display errors if there are any
$image = $this->upload_image();
if (!$image['exists'] && \Config::get('details.image.required', false) && empty($item->image)) {
// No previous images and image is not selected and it is required
\Messages::error('<strong>There was an error while trying to upload category image</strong>');
\Messages::error('You have to select image');
} elseif ($image['errors']) {
\Messages::error('<strong>There was an error while trying to upload category image</strong>');
foreach ($image['errors'] as $error) {
\Messages::error($error);
}
}
if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('details.image.required', false))) {
// Get POST values
$insert = \Input::post();
// Prepare some values
$insert['active_from'] = !empty($insert['active_from']) ? strtotime($insert['active_from']) : NULL;
$insert['active_to'] = !empty($insert['active_to']) ? strtotime($insert['active_to']) : NULL;
if ($insert['status'] != 2) {
unset($insert['active_from']);
unset($insert['active_to']);
}
$item = Model_Category::forge($insert);
try {
$item->save();
// Validate and insert category slug into SEO database table
$val_seo = Model_Category_Seo::validate('create_seo');
$insert_seo = array('content_id' => $item->id, 'slug' => \Inflector::friendly_title($item->title, '-', true));
while (!$val_seo->run($insert_seo)) {
$insert_seo['slug'] = \Str::increment($insert_seo['slug'], 1, '-');
}
$item_seo = Model_Category_Seo::forge($insert_seo);
$item_seo->save();
// END OF: SEO
// Insert category images
if ($this->_image_data) {
$item_image = array(array('id' => 0, 'data' => array('content_id' => $item->id, 'image' => $this->_image_data[0]['saved_as'], 'alt_text' => \Input::post('alt_text', ''), 'cover' => 1, 'sort' => 1)));
Model_Category::bind_images($item_image);
}
\Messages::success('Category successfully created.');
\Response::redirect(\Input::post('update', false) ? \Uri::create('admin/product/category/update/' . $item->id) : \Uri::admin('current'));
} catch (\Database_Exception $e) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create category</strong>');
// Uncomment lines below to show database errors
$errors = $e->getMessage();
\Messages::error($errors);
}
} else {
if ($val->error() != array()) {
// show validation errors
\Messages::error('<strong>There was an error while trying to create category</strong>');
foreach ($val->error() as $e) {
\Messages::error($e->get_message());
}
}
}
// Delete uploaded image if there is category saving error
if (isset($this->_image_data)) {
$this->delete_image($this->_image_data[0]['saved_as']);
}
}
\Theme::instance()->set_partial('content', $this->view_dir . 'create');
}