在我遵循 joomla“开发 MVC 组件”文档直到步骤 15-“添加 ACL”之后
Link - https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_ACL
一切正常,
但我没有看到任何关于创建前端类别视图的信息,所以我添加了一个新视图“类别”,这是我的代码:
在管理字段文件夹中,我创建了一个 hellocategory.php 大多数代码与 helloword 相同,只需更改
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();
视图.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);
}
}
默认.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>
默认的.php
<?php var_dump($category); ?>
没有输出,是否有关于在线创建类别文档或示例的任何内容?我尝试了 google 的解决方案四天,但仍然不知道,或者唯一的方法是从数据库中获取数据?