After i follow the Joomla "Developing an MVC Component" document until step 15- "Adding ACL" everything works. Then I tried add a new view "category", but it did not work.

Here is my code:

In admin fields folder I created a hellocategory.php most code same with helloword,just change

protected $type = 'HelloCategory';

 * Method to get a list of options for a list input.
 * @return  array  An array of JHtml options.
protected function getOptions()
    $db    = JFactory::getDBO();
    $query = $db->getQuery(true);
    // custom
    $query->select('#__categories.id as id,#__categories.title as category,#__categories.extension as exten');
    $query->where($db->quoteName('extension') . ' LIKE '. $db->quote('com_helloworld'));
    // end custom
    $db->setQuery((string) $query);
    $messages = $db->loadObjectList();
    $options  = array();
    if ($messages)
        foreach ($messages as $message)
            $options[] = JHtml::_('select.option', $message->category);

    $options = array_merge(parent::getOptions(), $options);

    return $options;


class HelloWorldViewCategory extends JViewLegacy
     * Display the Hello World view
     * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
     * @return  void
    function display($tpl = null)
        // Assign data to the view
        $category = $this->get('Item');

        // Check for errors.
        if (count($errors = $this->get('Errors')))
            JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');

            return false;

        // Display the view


<layout title="Category">
    <fieldset name="request">


<?php var_dump($category); ?>

output is Null

The Admin Menu works,but frontend can't get any items in that category data, is there any about develop single category view document or sample online? i tried google for solution four days,but still no idea, or the only way is get data from database? Many Thanks!

var_dump($this)will output

    object(HelloWorldViewCategory)#223 (15) { ["_name":protected]=> string(8) "category" ["_models":protected]=> array(0) { } ["_basePath":protected]=> 

string(55) "/var/www/clients/client0/web11/web/components/com_helloworld" ["_defaultModel":protected]=> NULL ["_layout":protected]=> string(7) "default" ["_layoutExt":protected]=> string(3) "php" ["_layoutTemplate":protected]=> string(1) "_" ["_path":protected]=> array(2) { ["template"]=> array(2) { [0]=>

 string(79) "/var/www/clients/client0/web11/web/templates/protostar/html/com_helloworld/category/"  bla bla bla....

2 Answers 2


Edit: Okay, now we have the bottom of your getOptions method(), the problem's in your view's display() method. $category is only available in the local scope of that method, you need to make it a class property.

In display() change:

$category = $this->get('Item');


$this->category = $this->get('Item');

In default.php:

  • Thanks for answer,in backend menu i can select a category,name and id correct,the question is i can't get data on frontend category view,by the way i did update my chellocategory.php code few minute ago
    – Anthony
    Commented Aug 12, 2016 at 16:53
  • Your '$category' variable is currently only available in the scope of your view's display() method, which is why you can't access it from default.php. You need to set it as a class property, so you should declare it using '$this->category' instead of just '$category'. var_dump($this->category) in your default.php should at least now output something.
    – Bathmat
    Commented Aug 12, 2016 at 17:53
  • confuse now...i did change $this->category = $this->get('Item'),and now var_dump($this->category) still output NULL,i update in question when var_dump($this) the output
    – Anthony
    Commented Aug 12, 2016 at 18:42
  • Do a var_dump($this->category) right after $this->category = $this->get('Item') in display(). That'll show the result of your database query, and it's probably null. What class is your getOptions() method in, and what class is it extending?
    – Bathmat
    Commented Aug 12, 2016 at 23:06
  • i found maybe i should add a document in site/models for category,but really not sure,do you know how many files should i create them for category show? thanks
    – Anthony
    Commented Aug 14, 2016 at 8:39

I'd suggest you to use link to index.php?option=com_categories&extension=com_YOUREXTENSION.

And add /helpers/yourextension.php file that will generate menu by having method

public static function addSubmenu($vName)
            $vName == 'entryone'
            $vName == 'entrytwo'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.