I have a anchor tag:
a href={{ path('edit_teacher', { slug: teacher.id}) }}>Edit</a
which gives URL like:
localhost:9000/edit-teacher/1
Here, I want to encrypt parameter '1' as I don't want the user to see the teacher Id. So I made a service to encrypt this Id.
Service :
namespace App\Service;
class EncryptGenerator
{
/**
* This function incrypts the data provided.
* @param: int/string.
*/
public function incryptData($data)
{
$incryptedData = convert_uuencode($data);
return $incryptedData;
}
/**
* This function decrypts the strings provided.
* @param: string.
*/
public function decryptedData($string)
{
$decryptedData = convert_uudecode($string);
return $decryptedData;
}
}
I have also added this service to twig file in twig.yaml.
twig:
default_path: '%kernel.project_dir%/templates'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']
globals:
my_service: "@App\\Service\\EncryptGenerator"
Lastly, I am not able to call this service by my twig file, below is what I am trying to anchor tag:
a href={{ path('edit_teacher',{ my_service.incryptData( slug: teacher.id }) }) }}>Edit
which gives me following error:
A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{".**