Jump to:

23377 Posts in 18296 Topics by 2868 members

General Questions

SilverStripe Forums » General Questions » onAfterWrite javascript Parse Error

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1535 Views
  • Bambii7
    Avatar
    Community Member
    254 Posts

    onAfterWrite javascript Parse Error Link to this post

    Hey All
    Any one else have a similar problem?
    I've included a Twitter class in Page, for auto tweeting after writing data.

    Goes like
       public function onAfterWrite()
       {
          parent::onAfterWrite();
          include('twitter.php');
          $t = new Twitter('****','****');
          $t->updateStatus("".$this->Title." http://www.mysite.com".$this->Link());
       }

    Everything still works fine, data is saved and tweet is sent.
    But I get two errors in base.js promoting me that errors occurred and it didn't go according to plan.

    From fire fox web tools plugin error console .
    "reference to undefined property jQuery.cache[id][name]"
    jQuery.cache[id][name]=data;return name?jQuery.cache[id][name]:id;},removeData:function(elem,name){elem=elem==window?windowData:elem;var id=elem[expando];if(name){if(jQuery.cache[id]){delete jQuery.cache[id][name];name="";for(name in jQuery.cache[id])

    And

    "reference to undefined property window.opera"
    if(window.opera&&['left','top','right','bottom'].include(style))

    Its probably a difficult thing to answer as it's an issue with my twitter class. Remove the twitter code and all works a charm. Just wondering if anyone had any pointers?

  • banal
    Avatar
    Community Member
    901 Posts

    Re: onAfterWrite javascript Parse Error Link to this post

    What twitter class did you use?
    Maybe try this one instead: http://code.google.com/p/twitter-php/

    Btw. you could also use AbsoluteLink instead of yourdomain + Link. Eg.

    $t->updateStatus($this->Title . ' ' . $this->AbsoluteLink());

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: onAfterWrite javascript Parse Error Link to this post

    Thanks for the reply banal. I was trying to find the AbsoluteLink, I remember seeing it a 6 months ago but couldn't remember.

    I'm using Twitter class by Tijs Verkoyen, tried that google code one you linked to and I get the exact some thing. It sends the tweet fine, but javascript error on save, although the content appears to save.

    It seems to be the include('twitter.class.php'); that's throwing it out.

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: onAfterWrite javascript Parse Error Link to this post

    Not best practice but I whacked the twitter class above the page class, and it works. Someone must have encountered this before, I'll try and find the correct way to include a custom class.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: onAfterWrite javascript Parse Error Link to this post

    I wasn't sure how PHP handles includes, but after reading this: http://www.php.net/manual/en/function.include.php it appears that if you put an include statement inside a function, the code will be included as if it was defined in the function.
    Maybe this causes the issue? Have you also tried include_once (just to be sure the class doesn't get included multiple times)?

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: onAfterWrite javascript Parse Error Link to this post

    I can't remember off hand, but that is a good point. I usually include files before the class. I'll give it a whirl

    1535 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.