The fastest way to assign language variables in the OpenCart controller.
The fastest way to assign language variables in the OpenCart controller. Probably the most boring thing in the OpenCart module development is assign language variables in the controllers.
First, you should add all the language variables into all the language files. Then you should every language variable add to the $data in the controller. Then you should every language variable add into the template file. If your module has 2 or 3 language variables it is not a problem. But in the most cases modules have dozens of variables and for every of them you should do this:
$this->language->load('path/file'); $this->data['foo1'] = $this->language->get('bar1'); $this->data['foo2'] = $this->language->get('bar2'); // dozens of the $this->language->get()
You can replace all these lines with just one:
// OpenCart 1.5.x $this->data = $this->language->load('path/file'); // OpenCart 2.0.x $data = $this->language->load('path/file');
Why this approach isn't used in the OpenCart core? Does anyone like to add dozens of the unnecessary lines of code into the controllers?..