Jump to content

Mathroth

Members
  • Posts

    7
  • Joined

  • Last visited

Posts posted by Mathroth

  1. On 10.4.2017 at 3:30 PM, rick said:

    Your function takes an argument but your hook is not passing one?

        public function myHook(HookEvent $e) {  
             $seconds = $e->arguments[0];
             $this->syncMobileDE($e);
             echo "30 seconds have passed!";
             
        }

    Changed it with the argument. Unfortunately the function doesn't execute. The "echo" is displayed on every page. So the error might be in the syncMobileDE() Function. I also use the function with a hook on "Pages::save" and there it works. :-X

      public function init() {
    		...
            $this->pages->addHookAfter('Pages::save', $this, 'syncMobileDE');
      }

     

  2. hello to all processwire dudes... I need your help again :lol: As you can see in my code i want to call a simple function i the processwire lazy cron hook. Lazy cron works and execute the "echo 30 seconds have passed!" But the function syncMobileDE();  does not return any results. Thanks for your advises! 

    public function init() {
            $this->addHook('LazyCron::every30Seconds', $this, 'myHook');
        }
    
    public function myHook(HookEvent $e) {  
             $seconds = $e->arguments[0];
             echo "30 seconds have passed!";
              $this->syncMobileDE();
        }
    
     public function syncMobileDE($event) {
            /** @var Page $page */
            $page = $event->arguments(0);
            if($page->template->name == 'fahrzeugangebot') {
               $this->listCars();
               $this->initDetail();
               $this->message("Mobile.de synchronisiert");
            }
        }

     

  3. On 3.4.2017 at 8:50 AM, BitPoet said:

    You have to perform the check for the template name inside your hook function. $this->page or wire('page') returns whatever page in which the module code is executed (admin page editor, custom page with the code...). Pages::save on the other hand is called with the page object being saved, which is what you're looking for.

    
    public function init() {
            $this->pages->addHookAfter('Pages::save', $this, 'syncMobileDE');
    }
    
    protected function syncMobileDE(HookEvent $event) {
    	$page = $event->arguments(0);
    	if($page->template->name == 'TemplateName') {
    		// Run your code
    	}
    }

     

    You made my day, now it works. Looks very logical and works quite well. Thanks to all for your advises. Have a nice weekend! 

  4. 1 hour ago, Robin S said:

    Needs the Pages class in there somewhere. Either:

    
    public function ready() {
        if($this->page->template->name == 'TemplateName') {
            $this->pages->addHookAfter('save', $this, 'syncMobileDE');
        }
    }

    Or:

    
    public function ready() {
        if($this->page->template->name == 'TemplateName') {
            $this->addHookAfter('Pages::save', $this, 'syncMobileDE');
        }
    }

     

    Unfortunately not! :-[ It just works if I save any of the pages – regardless which template the page is using. 

     public function init() {
            $this->pages->addHookAfter('Pages::save', $this, 'syncMobileDE');
    }

     

  5. 12 minutes ago, horst said:

    Hi, welcome to PW forums.

    Looks like you have not the right PHP syntax. Try this:

    
    public function init() {
        // you need a condition that will result to true
        if($this->page->template->name == 'templateName') {
    		$this->addHookAfter('save', $this, 'example1');
        }
    }

     

    Thanks for your help! Seems to be the right syntax now but unfortunately the function will not be fired. I also tried different templates...:'(

  6. Greetings to all processwire fans,

    I am new in processwire and I have used it since 3 weeks. Probably it's a really silly question but does someone now how I can execute a function in my own module, which is triggered when I save a pages, which contains a user-defined template. I tried to to this with an basic if/else condition to trigger the hook when the page has theTemplateName== "". Unfortunately it doesn't work. So I try this which might be the wrong Syntax. Perhaps someone can give me a hint ;) THANKS a lot! 

     

        public function init() {
    
            // add a hook after the $pages->save, to issue a notice every time a page is saved
       
            $this->page->template == "templateName"->addHookAfter('save', $this, 'example1');
     
        }

     

×
×
  • Create New...