Airship\Cabin\Bridge\Blueprint\Blog::createCategory PHP Method

createCategory() public method

Create a new category
public createCategory ( array $post ) : boolean
$post array
return boolean
    public function createCategory(array $post) : bool
    {
        $this->db->beginTransaction();
        $slug = $this->makeGenericSlug($post['name'], 'hull_blog_categories');
        $this->db->insert('hull_blog_categories', ['name' => $post['name'], 'parent' => $post['parent'] > 0 ? $post['parent'] : null, 'slug' => $slug, 'preamble' => $post['preamble']]);
        return $this->db->commit();
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create a new category
  *
  * @route blog/category/new
  */
 public function newCategory()
 {
     if (!$this->can('create')) {
         \Airship\redirect($this->airship_cabin_prefix . '/blog/category');
     }
     $post = $this->post(new NewCategoryFilter());
     if (!empty($post)) {
         if ($this->blog->createCategory($post)) {
             \Airship\redirect($this->airship_cabin_prefix . '/blog/category');
         }
     }
     $this->lens('blog/category_new', ['active_link' => 'bridge-link-blog-category', 'categories' => $this->blog->getCategoryTree()]);
 }