[英]How to pass array of data from Joomla view form and get the array of data in Joomla Controller
[英]How to get data from an input page in Joomla and use it in a controller
我有一个Joomla xml,其中定义了这两个字段:
<field
name="country_code"
type="sql"
default="10"
label="COM_TEAM_COUNTRY_CODE"
query="SELECT country_code, country FROM #__team_country"
key_field="country_code"
value_field="country"
/>
<field name="town"
type="text"
size="120"
class="inputbox span6"
label="COM_TEAM_FIELD_TOWN_LABEL"
description="COM_TEAM_FIELD_TOWN_DESC"
required="true" />
这两个字段使用函数进行更新,其余的则进行更新:
<?php
defined('_JEXEC') or die;
class TeamControllerTeam extends JControllerForm
{
function saveAndSetCity()
{
parent::save();
$jinput = JFactory::getApplication()->input;
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('town', 'country_code');
$newCCode = $jinput->get('country_code','','');
// Insert values.
$values = array($db->quote('newTown'), $db->quote($newCCode));
// Prepare the insert query.
$query
->insert($db->quoteName('#__team_city'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
// Set the query using our newly populated query object and execute it.
$db->setQuery($query);
$db->execute();
}
}
Parent :: save行将其存储在表中,但是我也想将特定的两个字段也存储在另一个表中,我找到并改编的代码可以正常工作,除了获得想要的实际值外存储,因为我还没有找到可以获取值的方法。 无论我如何尝试,我编写的代码仅存储固定的文字或空白。 我已经阅读了有关Jinput的Joomla文档页面,但是我不知道如何使用它。
善待彼得·杜鲁普
我发现我以错误的方式使用了JInput,并且我更改了代码,因此现在可以使用了。
<?php
defined('_JEXEC') or die;
class TeamControllerTeam extends JControllerForm
{
function saveAndSetCity()
{
parent::save();
$input = JFactory::getApplication()->input;
$formData = new JInput($input->get('jform','', 'array'));
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('town', 'country_code');
//$newCCode = $jinput->get('country_code','','STR');
$newTown = $formData->getWord('town');
$newCCode = $formData->getWord('country_code');
// Insert values.
$values = array($db->quote($newTown), $db->quote($newCCode));
// Prepare the insert query.
$query
->insert($db->quoteName('#__team_city'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
// Set the query using our newly populated query object and execute it.
$db->setQuery($query);
$db->execute();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.