Skocz do zawartości
"Idzie nowe..." - o zmianach i nie tylko ×
Przeniesienie zakupów z IPS Marketplace / Moving bought items from IPS Marketplace ×

[resources.invisionpower.com - pliki] Developer Articles > Creating a custom script with hooks


Rekomendowane odpowiedzi

  • Manager

This will run you through how to create a custom script when exporting a hook. This is option is only available in your acp when in_dev mode is enabled in your conf_global.php. You can export a hook by going to the Export Hook option on the Manage Hooks page.

The script requires you to firstly choose a filename this will always have to start with install_ and must be placed in your hooks directory. The second part of the filename is the name your class MUST be in the file. Below is an example of what a custom script can look like and some screenshots showing how to get to this page:

export1.jpg

export2.jpg

export3.jpg

class custom {

/**#@+
 * Registry Object Shortcuts
 *
 * @access	protected
 * @var		object
 */
protected $registry;
protected $DB;
protected $settings;
protected $request;
protected $lang;
protected $member;
protected $cache;	
protected $caches;
/**#@-*/

public function __construct( ipsRegistry $registry )
{
	/* Make objects */
	$this->registry = $registry;
	$this->DB		= $this->registry->DB();
	$this->settings =& $this->registry->fetchSettings();
	$this->request  =& $this->registry->fetchRequest();
	$this->lang		= $this->registry->getClass('class_localization');
	$this->member   = $this->registry->member();
	$this->memberData =& $this->registry->member()->fetchMemberData();
	$this->cache	= $this->registry->cache();
	$this->caches   =& $this->registry->cache()->fetchCaches();
}

public function install()
{
	# do something here
}

public function uninstall()
{
	# do something here
}
}

As you can see we need three default functions, the first being a constructor which will automatically be passed the registry object. You can then access any data you wish as shown in the example code. The second function required is a function called install. This function will automatically be run when your hook in installed. You can put whatever code you want in here. The third function will be run when the hook is installed so you can do any final cleanups in this function. Thats pretty much it, its quite simple but gives you a lot more flexibility.

intermedia - profesjonalne rozwiązania Invision Power Board

---

Chcesz uzyskać szybko i sprawnie pomoc? Uzupełnij wersję i adres w profilu.

Odnośnik do komentarza
Udostępnij na innych stronach

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Posiadasz już konto? Zaloguj się poniżej.

Zaloguj się
  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...

Powiadomienie o plikach cookie

Umieściliśmy na Twoim urządzeniu pliki cookie, aby pomóc Ci usprawnić przeglądanie strony. Możesz dostosować ustawienia plików cookie, w przeciwnym wypadku zakładamy, że wyrażasz na to zgodę.