Thank you guys for the responses, but I am still quite confused.
Let me try to expound on what I was trying to say earlier, perhaps it will clear up what my actual quandary is.
As I said, my goal is to build a CMS ‘framework’ … think of it as a different version of Wordpress, for example. The premise of my framework is a master object class ( I will refer to this class as MastObj, from this point on) and a set of supporting functions. Someone developing a template using this framework would include my class definitions and my supporting functions php files. I DIDNT WANT anyone altering those two files, especially altering the file with the MastObj class , not even to expand functionality.
Consequently it occurred to me that the output of any instance of MastObj could be done via “plugged in” or included code which would be written in separate flies.
- Generation 1 will be covered by using include_once. Module designers should use include_once themselves to prevent collision on Generation 2+ includes.
so module designer wouldn’t be altering the class, they would be writing only code that would plug into the loop of the output function of the MastObj class.
so for example, a template file would have this code:
...
$content=new MAstObj(mastobj parameters here...);
$sideNav=new MastObj(Mastobj parameters here...);
$footNav=new MastObj(Mastobj parameters here...);
echo'<div id="side"><ul>';
$sideNav->output('listItems');
echo'</ul></div>'
echo'<div id="main">;
$sideNav->output('content');
echo'</div>'
echo'<ul id="foot">';
$footNav->output('listItems');
echo'</ul>'
a ‘plugin’ file RM_listItems.php would be:
<? if ($this->params['headline']):?>
<li><a href="<? echo $this->params['base'].".php?cat=".$row['CatID'] ?>"><? echo $row['CatName']?></a> <? if (isset($this->params['shoCnt'])){if($this->params['shoCnt']){echo isset($this->params['eCount'][$row['CatID']])?" (".$this->params['eCount'][$row['CatID']].")":"(0)";}} ?>
</li>
<? endif?>
this would be included() into the $sideNav instance of MastObj when the function output is called. And you can see what I meant by it would execute natively, relying on properties of the class ($this->…) as if the plugh in code had been hard coded into the class.
another instance of the same class might call a completely different file for a plug in…
a ‘plugin’ file RM_content.php would be:
<? if ($this->params['headline']):?>
<? echo params['headline'];?>
<p>text</p>
<? endif?>
I was concerned that if I used include_once(), instead of include() that the "plugin"code would fail to include after the first item in the loop and OR in other instances of the class that attempt to include the same file.
At the same time… it just feels odd to call the SAME file on include to a loop. (is really is my question)
- Any ‘module’ included which fires output or executes commands directly as a result of it’s inclusion can only be called once if you use include_once (dur). Module designers must be aware to use function/method calls for any and all code.
I am not sure what you mean here. Again if you look at my sample plugin code… you will see it should be LIMITED to echoing, processing or returning data and independent of all other plugings ( sure it may rely on masters functions, or mastOjb methods… but that’s was my point in using include that it allows for the use of ‘$this->’ when creating a plugin.
- Beware of conflicting config editing. If a module relies on a charset being set, for example, and another module changes the charset, it can lead to issues. Also, obviously, uniqueness in naming functions. (These really arnt a framework-design issue, so much as a module-policing issue)
Yes that part I was aware of plug in would not be allowed to create functions. Essentially I am just trying to INJECT code into the MasterObj output function. maybe that’s what I should have said all along. lol.