This function is in Application
class
> mvc > php
private function splitUrl()
{
if (isset($_GET['url'])) {
// split URL
$url = trim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
$this->url_controller = isset($url[0]) ? $url[0] : null;
$this->url_action = isset($url[1]) ? $url[1] : null;
unset($url[0], $url[1]);
$this->url_params = array_values($url);
}
}
New edit
I have this class
class Page extends Controller
{
public function __construct(){
//echo parent::splitUrl()->this->url_action;
echo parent::$this->url_action;
}
public function index()
{
// removed lins
}
}
How to get $this->url_action
in extends functions ?
The field url_action should be protected (or public, but that's not recommend). So you can use this in child classes.
See below such as pseudoniem code:
In your parent:
class Foo
{
protected $url_action = 'something'; // or set it via setter
}
The child class:
class FooChild extends Foo // Now, child can access protected (and public) fields of its parent!
{
public function getFromParent()
{
return $this->url_action; // or what you want
}
}