Joomla 3 helloworld component category

by Anthony   Last Updated August 12, 2016 08:06 AM

After i follow joomla "Developing an MVC Component" Document until step 15- "Adding ACL"

Link - https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_ACL

everything works,

then i tried add a new view "category",but not work,

here is my code:

in admin fields folder,i create 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->from('#__categories');  
    $query->where($db->quoteName('extension') . ' LIKE '. $db->quote('com_helloworld'));
    // end custom
    $db->setQuery((string) $query);
    $messages = $db->loadObjectList();
    $options  = array();

view.html.php

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
        parent::display($tpl);
    }
}

default.xml

<layout title="Category">
        <message>category</message>
</layout>
<fields
        name="request"
        addfieldpath="/administrator/components/com_helloworld/models/fields"
        >
    <fieldset name="request">
        <field
                name="id"
                type="hellocategory"
                label="COM_UNOFD_UNOFD_FIELD_GREETING_LABEL"
                description="COM_UNOFD_UNOFD_FIELD_GREETING_DESC"
                />
    </fieldset>
</fields>

default.php

<?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!



Related Questions


Error on save of articles and categories

Updated October 23, 2017 17:10 PM

Joomla custom fields in mod_articles_category

Updated February 28, 2018 19:10 PM

Smart Search truncate the results

Updated June 25, 2018 15:10 PM