I’m reading opencart php source code, and I can’t figure this out.
Please take a look at function rewrite() at “$url = $rewrite->rewrite($url);”
<?php
class Url {
private $url;
private $rewrite = array();
public function link($route, $args = '', $connection = 'NONSSL') {
....
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
return $url;
}
public function addRewrite($rewrite) {
$this->rewrite[] = $rewrite;
}
}
?>
Why above code doesn’t generate error ?
The rewrite function is not defined in class Url, and class Url doesn’t extend anybody ??
But then I track deeper, it seems that function rewrite is at seo_url class.
class ControllerCommonSeoUrl extends Controller {
// Add rewrite to url class
if ($this->config->get('config_seo_url')) {
$this->url->addRewrite($this);
}
...
public function rewrite($link) {
if ($this->config->get('config_seo_url')) {
$url_data = parse_url(str_replace('&', '&', $link));
....
Why ? I don’t see any connection between ‘Url’ and this ‘ControllerCommonSeoUrl’ yet. Am I missing some concept here ? What I should do to understand these codes ? Need little guidance here.
Iterates over whatever values in:
And maybe that
Url->rewritearray contains an instance ofControllerCommonSeoUrl, that would explain why$rewrite->rewrite()callsControllerCommonSeoUrl->rewrite().Also, you’d do yourself a favor by trying to learn to use a debugger 🙂