Question: I'm trying to create simple function that can be executed on **any page**.

```
function something() {
    $string = 'Hello World'; 
    return $string;
}

```

Let's say I'm in the category page, I would just call `$a = something();` and it would return my value

Platform : OpenCart

*P.S. I'm still studying MVC architecture*

Answer: 
You can create a function in any opencart library (system/library/)

As example in system/library/document.php 

```
    function something() {
    $string = 'Hello World'; 
    return $string;
}

```

And use anywhere in openсart as 

```
$something=$this->document->something();

```

P/s code in header.tpl will not work in ajax or direct request
Matricore's answer worked perfectly for me, but I also had to construct the new class with the config and db available.

Code below:

```
class yourclassname {

    public function __construct($registry) {
        $this->config = $registry->get('config');
        $this->db = $registry->get('db');
    }

}

```

You can then run queries via $this->db->query("Your query here");