0

我试图使用代码检索类别和子类别的列表。

预期产出 -

Root Category 
   1st Level Category 1
   1st Level Category 2
      2nd Level Category 1
      2nd Level Category 2
   1st Level Category 3

这将是一个类别导航。登录的用户将根据查看访问级别看到它

方法1 -

我采取了如下类别 -

    $categories = JCategories::getInstance('Content', $options);
    $category = $categories->get('root');

它提供了巨大的对象数组(其中一部分粘贴在这里)。

object(JCategoryNode)[80]
  public 'id' => string 'root' (length=4)
  public 'asset_id' => string '0' (length=1)
  public 'parent_id' => string '0' (length=1)
  public 'lft' => string '0' (length=1)
  public 'rgt' => string '13' (length=2)
  public 'level' => string '0' (length=1)
  public 'extension' => string 'system' (length=6)
  public 'title' => string 'ROOT' (length=4)
  public 'alias' => string 'root' (length=4)
  public 'description' => string '' (length=0)
  public 'published' => string '1' (length=1)
  public 'checked_out' => string '0' (length=1)
  public 'checked_out_time' => string '0000-00-00 00:00:00' (length=19)
  public 'access' => string '1' (length=1)
  public 'params' => string '{}' (length=2)
  public 'metadesc' => string '' (length=0)
  public 'metakey' => string '' (length=0)
  public 'metadata' => string '' (length=0)
  public 'created_user_id' => string '42' (length=2)
  public 'created_time' => string '2011-01-01 00:00:01' (length=19)
  public 'modified_user_id' => string '0' (length=1)
  public 'modified_time' => string '0000-00-00 00:00:00' (length=19)
  public 'hits' => string '0' (length=1)
  public 'language' => string '*' (length=1)
  public 'numitems' => null
  public 'childrennumitems' => null
  public 'slug' => string '1:root' (length=6)
  public 'assets' => null
  protected '_parent' => null
  protected '_children' => 
    array (size=1)
      0 => 
        object(JCategoryNode)[20]
          public 'id' => string '2' (length=1)
          public 'asset_id' => string '27' (length=2)
          public 'parent_id' => string 'root' (length=4)
          public 'lft' => string '1' (length=1)
          public 'rgt' => string '2' (length=1)
          public 'level' => string '1' (length=1)
          public 'extension' => string 'com_content' (length=11)
          public 'title' => string 'Uncategorised' (length=13)
          public 'alias' => string 'uncategorised' (length=13)
          public 'description' => string '' (length=0)
          public 'published' => string '1' (length=1)
          public 'checked_out' => string '0' (length=1)
          public 'checked_out_time' => string '0000-00-00 00:00:00' (length=19)
          public 'access' => string '1' (length=1)
          public 'params' => string '{"target":"","image":""}' (length=24)
          public 'metadesc' => string '' (length=0)
          public 'metakey' => string '' (length=0)

如何根据需要获取父类别及其子类别的名称?请注意,我需要使用视图访问级别对其进行过滤。

方法2 -

获取登录用户的授权视图级别

$levels = JAccess::getAuthorisedViewLevels($userid);

将其加载到数组中-

foreach ($levels as $level){
            $vacl[] = "access = ".$level;
        }

执行了数据库查询 -

$db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $query->select(array('extension', 'title', 'access','params'));
        $query->from('#__categories');

        $query->where($vacl,'OR')->where('extension ='.$db->quote('com_content'),'AND');
        $db->setQuery($query);
        $results = $db->loadObjectList(); 

问题是 OR 并且 AND 没有按预期工作。我该如何纠正它?

4

0 回答 0