×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
PHP in filter xml
Mekalb
New Member
Posts: 8
8 года 10 мес. назад #1190
от Mekalb
Mekalb создал тему: PHP in filter xml
Good Morning,
I'm creating a filter for one of my forms. I'm currently using php to get the userId, and use that to filter a foreign key.
As you can see below, the code I am using is <?php echo 89; ?> (I've hard-coded it for testing purposes).
Sadly this is not working. Anyone know what I'm doing wrong? Is there a way to do it only via xml?
Thanks.
component_name/models/forms/myform.xml
<field name="filter_firstname" type="sql" class="inputbox"
onchange="this.form.submit();"
query="SELECT 0 AS `created_by`, '- Please select First name -' AS `first_name` UNION SELECT `created_by`, `first_name` FROM `#__applicationportal_names` WHERE `created_by`=<?php echo 89; ?>" key_field="created_by" value_field="first_name"
/>
I'm creating a filter for one of my forms. I'm currently using php to get the userId, and use that to filter a foreign key.
As you can see below, the code I am using is <?php echo 89; ?> (I've hard-coded it for testing purposes).
Sadly this is not working. Anyone know what I'm doing wrong? Is there a way to do it only via xml?
Thanks.
component_name/models/forms/myform.xml
<field name="filter_firstname" type="sql" class="inputbox"
onchange="this.form.submit();"
query="SELECT 0 AS `created_by`, '- Please select First name -' AS `first_name` UNION SELECT `created_by`, `first_name` FROM `#__applicationportal_names` WHERE `created_by`=<?php echo 89; ?>" key_field="created_by" value_field="first_name"
/>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Mekalb
New Member
Posts: 8
8 года 10 мес. назад #1195
от Mekalb
Mekalb ответил в теме PHP in filter xml
Here is the solution if anyone else is interested.
/models/fields/foreignkey.php
Navigate to:
$query->select(
array(
$db->quoteName($this->key_field),
$db->quoteName($this->value_field)
)
)->from($this->table);
//Add the following code to append condition to the query.
if ($this->getAttribute('name') == 'firstname')
{
$query->where($db->quoteName('created_by') . ' = ' . (int) JFactory::getUser()->id);
}
Thanks to CC guys for the solution.
/models/fields/foreignkey.php
Navigate to:
$query->select(
array(
$db->quoteName($this->key_field),
$db->quoteName($this->value_field)
)
)->from($this->table);
//Add the following code to append condition to the query.
if ($this->getAttribute('name') == 'firstname')
{
$query->where($db->quoteName('created_by') . ' = ' . (int) JFactory::getUser()->id);
}
Thanks to CC guys for the solution.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Время создания страницы: 0.050 секунд