Skip to content
Advertisement

PHP MVC: How to add translation strings to views?

In my MVC view files, there exist strings I may have a translation for. In a file with access to the database (the model), I can do:

JavaScript

Here is what it’s doing:

JavaScript

I need access to this say() function from within my view. Short of passing the entire vocabulary array to the view, how would I do this?

Advertisement

Answer

What you need to do is require_once your .php file that contains your class. You can then instantiate your class into a object like $Lang and call $Lang->Say() from your view.

For example:

JavaScript

Now you can do whatever it is you need to do with the string.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement