Jump to content

AddHook causes error 324


verdeandrea
 Share

Recommended Posts

Hi guys,

i've working on this site based on pw. I'm getting the error 324 err_empty_response in my homepage, but soon as i delete this line

wire()->addHook("Page::wordLimiter", null, "wordLimiter");

everything is working fine again. 

This is the complete code of the hook

function wordLimiter(HookEvent $event){
    $field = $event->arguments[0]; // first argument
    $limit = $event->arguments[1];
    $endstr = isset($event->arguments[2]) ? $event->arguments[2] : ' …';
    $page = $event->object; // the page
    $str = $page->get($field);
    $str = strip_tags($str);
    if(strlen($str) <= $limit) return;
    $out = substr($str, 0, $limit);
    $pos = strrpos($out, " ");
    if ($pos>0) {
        $out = substr($out, 0, $pos);
    }
    return $event->return = $out .= $endstr;
}
wire()->addHook("Page::wordLimiter", null, "wordLimiter");

and is written on the top of the page.

I really don't get what can cause that problem. Could you please help and suggest what can be wrong? Thanks

Link to comment
Share on other sites

Hi verdeandrea,

What happens if you try this...

function wordLimiter(HookEvent $event){
    $field = $event->arguments[0]; // first argument
    $limit = $event->arguments[1];
    $endstr = isset($event->arguments[2]) ? $event->arguments[2] : ' …';
    $page = $event->object; // the page
    $str = $page->get($field);
    $str = strip_tags($str);
    if(strlen($str) <= $limit) return;
    $out = substr($str, 0, $limit);
    $pos = strrpos($out, " ");
    if ($pos>0) {
        $out = substr($out, 0, $pos);
    }
    $out .= $endstr;
    $event->return = $out;
}

...?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...