[Typo3-dev] Guide to slightly advanced programming in typo3?

Robert Lemke rl at robertlemke.de
Mon Apr 19 18:36:22 CEST 2004


On Mon, 2004-04-19 at 17:43, Mathias Schreiber [K1net] wrote:
> I have a little problem:
> We have to do a project that involves several people programming on the same
> extension at once.
> For me the best way would be, if I could seperate certain parts of the
> extension (shopping basket, products display) in its own files.
> So something like class.shop_basket.php and so on.
> My problem is how do I pass $this->cObj to the different classes?
> 
> Since this is quite urgent I am willing to pay for a short online training
> if this raises my chances of getting an answer ;-)

That depends. In many cases you could use the $TSFE->cObj but in many
others you'll have to create your own.

So in the latter case I'd use the singleton design pattern. Here you go:

In your main class you create a function like this:

class mybaseclass {
   function &getCObjInstance()  {
      static $instance;
      if (!isset ($instance)) {
         $instance = t3lib_div::makeInstance('tslib_cObj');
      }
      return $instance;
}

Then, in all your other classes, it goes like this:

class myclassname {
   var $cObj;

   function myclassname () {
      $this->cObj =& mybaseclass::getCObjInstance;
   }
}

This advice was for free ;-)

-- 
robert

"They placed me on this earth without a manual. 
 And I dare to say, I’m doing just fine without ;)"






More information about the TYPO3-dev mailing list