How can I design a pattern that can affect calling methods of a class and getting an output from them, for example when we use return $this we can constantly call multiple methods using pointers but in this approach, we cant affect the previous called method through the last called method..
Instance code :
layout1.php
|--------------|
<div>
{content}
</div>
index.php
|-----------|
//return output
$view->layout('layout1')->content('test');
In case the instance code changed to the following
//echo output
$view->layout('layout1');
I need the function to be informed and show a different behavior on sending the output. For instance , in the first code the output value should be returned but in the second one, the value must be directly echoed..
Sample code :
layout1.php
|--------------|
<div>
{content}
</div>
index.php
|-----------|
$view = view();
//return output
$view->layout('layout1')->content('test');
//echo output
$view->layout('layout1');
view.php
|-----------|
class view{
public function layout($file){
return $this;
}
public function content($html){
return $this;
}
}
Thank you very much in advance for your help...
Aucun commentaire:
Enregistrer un commentaire