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->from('#__categories');
$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;
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!
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....