Jump to content
Дизайн и модификация Invision Community IPBSkinsBETA
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
siv1987

Передача регистра из одного класса в другой

Recommended Posts

Я правильно понимаю концепцию ипс и ООП о передаче регистра из класса в класс?

 

class lofi
{
   public function __construct( ipsRegistry $registry )
   {
       $this->registry = $registry;
       $this->DB       = $this->registry->DB();
       .....
   }

   public function init()
   {
       $this->skin = new lofi_skin( $this->registry )
   }
}


class lofi_skin
{
   public function __construct( ipsRegistry $registry )
   {
       $this->registry = $registry;
       $this->DB       = $this->registry->DB();
   }
}

$registry = ipsRegistry::instance();
$registry->init();

$lofi = new lofi( $registry );
$lofi->init();

 

Или можно как-то по другому? :)

Share this post


Link to post

Передавать каждый раз не обязательно, ipsRegistry - синглтон.

 

class lofi
{
   public function __construct( )
   {
       $this->registry = ipsRegistry::instance();
       $this->DB       = $this->registry->DB();
       .....
   }

   public function init()
   {
       $this->skin = new lofi_skin( );
   }
}

class lofi_skin
{
   public function __construct( )
   {
       $this->registry = ipsRegistry::instance();
       $this->DB       = $this->registry->DB();
   }
}

// Эта конструкция вызывается один раз на весь скрипт
$registry = ipsRegistry::instance();
$registry->init(); 
// ---

$lofi = new lofi();
$lofi->init();

  • Upvote 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...