Categories

Create a category

You can create a new category by calling the add method of the category controller:

<?php
$category_details = [
    'title' => 'category title'
];
$result = Koowa::getObject('com://site/docman.controller.category')
    ->add($category_details);

Fetch categories

For fetching categories, we set permission values for the current user, limit the results to 50 categories, and call the browse event.

<?php
// Get the controller
$controller = Koowa::getObject('com://site/docman.controller.category');
$user       = Koowa::getObject('user');
// Fetch all categories
$categories = $controller
    ->access($user->getRoles()) // Permissions
    ->current_user($user->getId())
    ->enabled(1) 
    ->limit(50)   // Limiting to 50 categories
    ->offset(0)   // You can set this to 50 in the next call to paginate results
    ->browse();
foreach ($categories as $category){
    var_dump($category->title);
}