Jump to content
dev123

function getting run twice

Recommended Posts

public static function getModuleInfo() {

		return array(

			'title' => 'Hello World',
			'version' => 101, 
			'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.',
			'href' => 'http://www.processwire.com',
			'singular' => true, 
			'autoload' => true, 
			);
	}

	public function init() {
		$this->pages->addHookAfter('trash', $this, 'example5');
	}

	
	public function example5($event){
		$this->message("TRASHed");
	}

I just edited helloworld module to add hook after trash ...I have succesfully added hook after save, but this after trash hook doesnt seem to work for me .

Pls guide where am i goin wrong .

What happens is when i delete a page(added to trash), this message "TRASHed " appears twice as in the snapshot.

post-2174-0-67528400-1395658143_thumb.pn

Share this post


Link to post
Share on other sites
<?php


class Helloworld extends WireData implements Module {

	
	public static function getModuleInfo() {

		return array(

			'title' => 'Hello World',
			'version' => 101, 
			'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.',
			'href' => 'http://www.processwire.com',
			'singular' => true, 
			'autoload' => true, 
			);
	}

	
	public function init() {
		$this->pages->addHookBefore('trash', $this, 'example5');
	}

	public function example5($event){
		if ($this->skipme) return;
		$this->message("TRASHed");
		$this->skipme=true;
	}

For some reason this example 5 function was running twice on trashing one page ...So this solved my problem .But i still dont get it why is it running twice

Share this post


Link to post
Share on other sites

I'm not sure, but it may doing something when trashing a page and save that page again so it ends up in trash. Very likely. Your solution is perfect to go. But maybe you can aslo just use the Pages::trashed instead as this would be just once after the page is trashed.

  • Like 1

Share this post


Link to post
Share on other sites

This is also wrong board.

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...