×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
Add menu parameter
Rob van Oudheusden
New Member
Posts: 3
10 năm 4 tháng trước #111
bởi Rob van Oudheusden
Add menu parameter was created by Rob van Oudheusden
Hello to you all,
I am new here and still learning Joomla development.
I have build a component with Component Creator, I added some custom functions and queries, and it works fine so far.
Now my question
The component has default 2 menu options: one for the list view (all items) and one for the single view (single item by ID).
In the component frontend I have only one main view (single and list) active, There are several foreign keys for this main part to other tables. These work fine. The information on both single and list view are correctly displayed, the way I want.
But now I want to add menu item parameters as options to select one or more of the foreign key items as a list, like Joomla does with category views to select a category to display all the items that belong to that category. I have searched on the internet and learned a bit about it, but I do not get it working at all. I know you have to add a field in the default.xml file of the frontend list view and then I get lost. I see a menu option in the backend, without the options, just an empty select field. I know I have to do a lot more, but I do not know what or where to start.
Can someone guide me with a step by step instruction, or give me a link to a good tutorial or send me some examples. Please do not advise me to view the Hello World custom component tutorial of Joomla. This does not help me at all. I hope someone will give me some good directions.
Best wishes,
Rob van Oudheusden,
Joomla CSS.
I am new here and still learning Joomla development.
I have build a component with Component Creator, I added some custom functions and queries, and it works fine so far.
Now my question
The component has default 2 menu options: one for the list view (all items) and one for the single view (single item by ID).
In the component frontend I have only one main view (single and list) active, There are several foreign keys for this main part to other tables. These work fine. The information on both single and list view are correctly displayed, the way I want.
But now I want to add menu item parameters as options to select one or more of the foreign key items as a list, like Joomla does with category views to select a category to display all the items that belong to that category. I have searched on the internet and learned a bit about it, but I do not get it working at all. I know you have to add a field in the default.xml file of the frontend list view and then I get lost. I see a menu option in the backend, without the options, just an empty select field. I know I have to do a lot more, but I do not know what or where to start.
Can someone guide me with a step by step instruction, or give me a link to a good tutorial or send me some examples. Please do not advise me to view the Hello World custom component tutorial of Joomla. This does not help me at all. I hope someone will give me some good directions.
Best wishes,
Rob van Oudheusden,
Joomla CSS.
Vui lòng Đăng nhập hoặc Tạo tài khoản để tham gia cuộc hội thoại.
Sigitas Petrauskas
New Member
Posts: 1
10 năm 3 tháng trước #177
bởi Sigitas Petrauskas
Replied by Sigitas Petrauskas on topic Add menu parameter
Did you tryed to use JCATEGORY fields withing Jomla ComponentCreator (Joomla CC)? try that feature first.
Vui lòng Đăng nhập hoặc Tạo tài khoản để tham gia cuộc hội thoại.
Rob van Oudheusden
New Member
Posts: 3
10 năm 3 tháng trước - 10 năm 3 tháng trước #186
bởi Rob van Oudheusden
Replied by Rob van Oudheusden on topic Add menu parameter
Herllo Petrauskas,
Thank you for your response.
There are two reasons why I do not want to use the JCATEGORY option.
1. I am learning to develop Joomla components, and I want to know how to do this without using this option.
2. I have only asked help for the use of on one menu filter item, but in fact I want multi items to filter within the menu,
In the meantime I have found out how this is working.
There is realy no documentation about this subject, so I found it out myself.
Here I will give the solution I found for other developers, who also want to know this.
I am also open for other methods and suggestions.
I updated 3 files from the default output of component creator.
default.xml of the frontend list view.
a new file in models/fields in the backend
added query code in the model for the frontend listview.
I am developing a realestate component and the most important frontend view is the properties/objects list view, which I want the user to narrow the list of default all objects to objects of a specific market.
Now I have 2 markets in the database in seperate table for markets wich has a relation with the properties table with a foreign key field..But the users can add as much markets as they want.
property for sale
property to rent
Frontend properties List view
The tmpl/default.xml file is als follows
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_REALESTATE_TITLE_LIST_VIEW_PROPERTIES" option="View">
<message>
<![CDATA[COM_REALESTATE_TITLE_LIST_VIEW_PROPERTIES_DESC]]>
</message>
</layout>
<fields name="request">
<fieldset
name="request"
addfieldpath="/administrator/components/com_realestate/models/fields"
>
<field
name="id"
type="marketlist"
label="Select a Market"
description="Select a Market"
>
<option value="0">All Markets</option>
</field>
</fieldset>
</fields>
</metadata>
The fieldtype will be the name of a new file in the
backend models/fields/marketlist.php
<?php
// No direct access to this file
defined('_JEXEC') or die;
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
/**
* MarketList Form Field class for the Realestate component
*/
class JFormFieldMarketList extends JFormFieldList {
/**
* The field type.
*
* @var string
*/
protected $type = 'MarketList';
/**
* 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);
$query->select('p.id, p.market, m.market_name');
$query->from('#__realestate_properties AS p');
$query->join('LEFT', '#__realestate_markets AS m ON m.id = p.market');
$db->setQuery((string)$query);
$markets = $db->loadObjectList();
$options = array();
if ($markets) {
foreach($markets as $market) {
$options[] = JHtml::_('select.option', $market->market, $market->market_name);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
So far the menu selection is extended with the option to slelect a market, which is a value in the database.
In this example the user can choose to select all markets, and the markets which are in the database.
To filter the market I added some code on the query in the
List model properties of the frontend
protected function getListQuery() {
......
// Menu selection List
$app = JFactory::getApplication();
$menus = $app->getMenu();
$title = null;
$menu = $menus->getActive();
$selectmarket = $menu->query;
.......
$query ->select('m.market_name, m.state as m_state, m.language as m_language')
->join('LEFT', '#__realestate_markets as m ON m.id = a.market')
->where('m.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
if ($selectmarket != 0) {
$query->where('m.id = ' .$selectmarket);
}
.....
Now you can select a menu option to All items or a specific market.
The listview in the frontend will only show the selected market.
That's it.
Thank you for your response.
There are two reasons why I do not want to use the JCATEGORY option.
1. I am learning to develop Joomla components, and I want to know how to do this without using this option.
2. I have only asked help for the use of on one menu filter item, but in fact I want multi items to filter within the menu,
In the meantime I have found out how this is working.
There is realy no documentation about this subject, so I found it out myself.
Here I will give the solution I found for other developers, who also want to know this.
I am also open for other methods and suggestions.
I updated 3 files from the default output of component creator.
default.xml of the frontend list view.
a new file in models/fields in the backend
added query code in the model for the frontend listview.
I am developing a realestate component and the most important frontend view is the properties/objects list view, which I want the user to narrow the list of default all objects to objects of a specific market.
Now I have 2 markets in the database in seperate table for markets wich has a relation with the properties table with a foreign key field..But the users can add as much markets as they want.
property for sale
property to rent
Frontend properties List view
The tmpl/default.xml file is als follows
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_REALESTATE_TITLE_LIST_VIEW_PROPERTIES" option="View">
<message>
<![CDATA[COM_REALESTATE_TITLE_LIST_VIEW_PROPERTIES_DESC]]>
</message>
</layout>
<fields name="request">
<fieldset
name="request"
addfieldpath="/administrator/components/com_realestate/models/fields"
>
<field
name="id"
type="marketlist"
label="Select a Market"
description="Select a Market"
>
<option value="0">All Markets</option>
</field>
</fieldset>
</fields>
</metadata>
The fieldtype will be the name of a new file in the
backend models/fields/marketlist.php
<?php
// No direct access to this file
defined('_JEXEC') or die;
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
/**
* MarketList Form Field class for the Realestate component
*/
class JFormFieldMarketList extends JFormFieldList {
/**
* The field type.
*
* @var string
*/
protected $type = 'MarketList';
/**
* 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);
$query->select('p.id, p.market, m.market_name');
$query->from('#__realestate_properties AS p');
$query->join('LEFT', '#__realestate_markets AS m ON m.id = p.market');
$db->setQuery((string)$query);
$markets = $db->loadObjectList();
$options = array();
if ($markets) {
foreach($markets as $market) {
$options[] = JHtml::_('select.option', $market->market, $market->market_name);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
So far the menu selection is extended with the option to slelect a market, which is a value in the database.
In this example the user can choose to select all markets, and the markets which are in the database.
To filter the market I added some code on the query in the
List model properties of the frontend
protected function getListQuery() {
......
// Menu selection List
$app = JFactory::getApplication();
$menus = $app->getMenu();
$title = null;
$menu = $menus->getActive();
$selectmarket = $menu->query;
.......
$query ->select('m.market_name, m.state as m_state, m.language as m_language')
->join('LEFT', '#__realestate_markets as m ON m.id = a.market')
->where('m.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
if ($selectmarket != 0) {
$query->where('m.id = ' .$selectmarket);
}
.....
Now you can select a menu option to All items or a specific market.
The listview in the frontend will only show the selected market.
That's it.
Last edit: 10 năm 3 tháng trước by Rob van Oudheusden.
Vui lòng Đăng nhập hoặc Tạo tài khoản để tham gia cuộc hội thoại.
Thời gian tải trang: 0.052 giây