Categories > TinyButStrong general >

OOP Related Subtemplates

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Sven Jansen
Date: 2006-07-27
Time: 14:38

OOP Related Subtemplates

Hi Folks!

First I want to say, that TBS is awesome!

But when I changed from Version 2 to 3 I got a lot of trouble with my CMS. I programmed it completely by myself, so I know the Code and Stuff really good.

You have to know, that my System is completely OO and so there are a lot of cool possibilities, e.g. inheritance, overloading and so on...

I'm using modules for managing the Content. There are 2 different Tyes. "Generic"-Ones with a global Template, calling an inherited function, with complete different functionality in it. And "Individual"-Ones with complete different Templates and Functions.

The problem where I ran into was at the "Generic"-Ones, they displayed always the same Content of the first module on the site...

After Debugging hours and hours (thanks ZDE) I found the Tricky Part:

FILE: tbs_class_php5.php
ROW: 2201

There is a "Cache" for called "onformat"-userfunctions, which sets references to objects. Good Programmers may get what happened :) It deters the functionality of my inherited functions and calls everytime the function of the first "Generic"-module :)

If you get into the same trouble here is the solution... (maybe the TBS programmer knews a better way). Comment out the check and return of the "Cache"-System for "onformat"-userfunctions.

function meth_Misc_UserFctCheck(&$FctInfo,&$ErrMsg,$DataFct) {
    $Ref = ($FctInfo[0]==='~');
    /*
    if (isset($this->_UserFctLst[$FctInfo])) {
        if ($Ref) $FctInfo = $this->_UserFctLst[$FctInfo];
        return true;
    }
    */

I hope this helps someone, if not... forget it :)

Sven Jansen
By: Skrol29
Date: 2006-07-27
Time: 15:13

Re: OOP Related Subtemplates

Hi Sven,

Thank for sharing this info.
I'll try to fix that in a next version.  But not caching object info may have a cost for those who use OOP a lot with TBS. I hope I'll find a trick for that.
By: Skrol29
Date: 2006-08-11
Time: 16:52

Re: OOP Related Subtemplates

Hi,

I'm working on TBS version 3.2.0 and it seems that the best way to avoid your problem is to code:
TBS->_UserFctLst = array();
when needed. That is when you think that your class has been extended. This line clears the cache of functions.
Doing this way, it keeps that function cache working. Which I think is quite usefull for optimization.

Another solution should be to upgrade TBS to make possible to avoid the function cache. For exemple, user could code the following in order to avoid the function cache:
TBS->_UserFctLst = false;
By: Sven Jansen
Date: 2006-08-11
Time: 18:10

Re: OOP Related Subtemplates

All my classes are extended. Maybe I should give a little sample. I talked about "Generic"-modules in my first post.

All "Generic"-modules which can display something inherit from a base-class with a function called "RenderContent". This function is called by following TBS-template which I use for all generic modules.

<div class="module">
    <div class="topic">[var.~Name;magnet=div;noerr]</div>
    <div class="content">
        [var.~Id;onformat=~RenderContent;subtpl]
    </div>
</div>

Each module displayes something else, so this function differs in each.

Now is the time for caching :) The cache-system finds the same functioncall and *bamm* calls the wrong "RenderContent" reference.

Maybe it would be clever to implement a class-check with get_class(). I think it would be nicer to implment a class check into it, rather than disabling it complete.

Maybe I'll get the time for implementing it, but you must decide if you want that :) It's in the core of your system and you know it surely better than I do.
By: Skrol29
Date: 2006-10-11
Time: 01:25

Re: OOP Related Subtemplates

TBS 3.2.0 RC 2 has an undocumented property.

$TBS->RecheckObj = true;
It makes the ObjectRef links to not be cached anymore.
By: Sven Jansen
Date: 2006-10-11
Time: 18:14

Re: OOP Related Subtemplates

Thank you :)