XF 2.2 Select row with array()

mcatze

Well-known member
Hey everybody,

i have a template with a selectrow. With foreach i got the data from the array(). So far so good.
In the select row are all data from the array shown, but how can i get all data saved to the db?

I tried with name="data()" value="$data()" but it doesn't work.

I hope i describe my problem clear enough.
 

Attachments

  • Bildschirmfoto 2021-03-28 um 12.26.21.webp
    Bildschirmfoto 2021-03-28 um 12.26.21.webp
    16.3 KB · Views: 20
  • Bildschirmfoto 2021-03-28 um 12.26.56.webp
    Bildschirmfoto 2021-03-28 um 12.26.56.webp
    29.2 KB · Views: 20
Last edited:
Unless you were passing an anonymous function in $leagues, $leagues() is not valid php syntax. () is a function call with zero arguments, and you can only call functions, hence the name.

Furthermore, your name attribute is the html input name, and thus follows normal conventions for that. name for a single value input and name[] for a multi selection.

Lastly, your value attribute on the selectrow must either be a single option value for single selects, or an array of option values for a multi select.
 
Hi, :) is this a multiple selection input row? If so, you need to add multiple="true" size="xxx" to the select row, and its name needs to be an array: name="leagues[]", and the value="{$leagues[]}. If it is not multiple selection then the name can just be "league", and the value "{$league}".

The value for your select row should not be the same variable used to generate the options, it should be the one where the members choice(s) were fetched from, ie: $profile.leagues, or $profile.league (depending).
 
Okay, that makes sense. Actually i am at the coding-level "Try & Fail".. ;)

I got from the $viewParams an array called $leagues[] with the following values.
  • $league.league_id
  • $league.name
  • $league.code
  • $league.logo
  • $league.country_code

In the admin options i try to show a selectable entry labeled with the name and after choice and save, all values should be stored in the db.

What could be the finest/cleanest way to do this? When i understand correctly, the selectrow isn't it.
 
This is a single selection, then? All you need is to send the league_id to the controller. In the controller all the other data associated with that league_id will be selected when you verify the id is legitimate: ie:

PHP:
$leagueId = $this->filter('league_id', 'uint');
$league = $this->em()->find('YourAddonId:League', $leagueId);
if (!$league)
{
    throw $this->exception($this->notFound(\XF::phrase('your_phrase_prefix_requested_league_not_found')));
}
Now that you have all the data associated with the selected league_id, you can save it, :)

Edit: fixed the addonId portion.
 
Last edited:
That could be tricky 'cause all data are served by an API. I will try it and maybe sometimes not fail. ;)

Thanks for that snippet.
 
Back
Top Bottom