XF 2.1 Passing php variable to phrase

Cupara

Well-known member
I'm trying to take a variable and pass it to my error phrase. The problem I'm having it figuring out how it works.

I have this:
PHP:
return $this->assertRecordExists('Leagues:Leagues', $id, $with, $phraseKey ?: 'bc_admin_league_not_found');

The result I'm trying to get it similar to this:
PHP:
return $this->error(\XF::phrase('bc_admin_league_not_found', ['leagueName' => $leagueName]));

If I use the following:
PHP:
return $this->assertRecordExists('Leagues:Leagues', $id, $with, $phraseKey ?: 'bc_admin_league_not_found', ['leagueName' => $league->league_name]);

I get an error of mysqli:real_escape_string error, expecting string but array is given or something like that.

Another issue I discovered is that when I try to pass the league_name, only id is passed.
PHP:
protected function assertLeagues($id, $with = null, $phraseKey = null)
    {
        return $this->assertRecordExists('Leagues:Leagues', $id, $with, $phraseKey ?: 'bc_admin_league_not_found');
    }

I changed $id to $params but only id is still passed. I'm not sure what else to go with as I have a ton of work left on this project so I need to move on to the next page so that is why I'm posting here so I can move on for now and come back to it later once I find a resolution through help here or figure it out after I lose all my hair from pulling it all out. LMAO

Anyway, thanks to anyone who can lend some assistance.
 
Last edited:
Hi @Mythotical,

Removed comment about Ternary Operator as all good for PHP 5.3 and up (too many php versions used out there).

The assertRecordExists() seems to only handle the phrase title with no parameters. See Mvc/Controller.php
You would probably need to either extend that function to check for your incoming phrase (league name) and then return a phrase with your parameters, or simply run your own record check in assertLeagues().
 
Last edited:
Back
Top Bottom