1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get prefix_id of current thread

Discussion in 'XenForo Development Discussions' started by Marcel, Dec 17, 2013.

  1. Marcel

    Marcel Active Member

    After having a crash course into the land of PHP beyond my basic capabilities, coupled with an in-flight meal of OOP, served with side dishes of classes, methods, controllers etc....I have managed to put together my very first plugin.

    The idea for the plugin is to have a 'One click' prefix at the top of a thread, which adds a pre-chosen prefix to the thread. (Which I've set up in the Admin options).
    I know this task is simple enough with "Thread tools > Edit > Choose Prefix > Save".

    Anyway, I've got the plugin working with the following action / route


    Which does exactly what I want it to, changes the prefix to the one I've chosen in the options, no frills no fuss. Now I've got this working I want to tidy up the code, adding proper authentication checks, error messages etc.

    Firstly, I want to check if the thread has our "Sold" prefix already, and if so, return out with an error.

    I get the thread info via this line in the method

    $thread = $this->getModelFromCache('XenForo_Model_Thread')->getThreadById($threadId);

    Does $thread now contain the prefix ID? If it does, I can't find it...what in-between scouring and searching the XenForo files and google.
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Have you dumped the param to see what's available?

    In the php: Zend_Debug::dump($thread);

    In the template: {xen:helper dump, $thread}
  3. Marcel

    Marcel Active Member

    Yeah I've just done that (Edited {xen:helper dump, $thread} into the thread_view template

    It does give me :
    ["prefix_id"] => int(1)

    But if I try and use it, it gives me a ......

    Oh bumchops, I know what I've done, one sec/
  4. Marcel

    Marcel Active Member

    Yup, that sorted it.
    It must have a been a gremlin in the system, and absolutely in no way associated with the fact I was using
    $thread->prefix_id instead of $thread['prefix_id'] in the conditional.
    Nope, not that at all.

    I think it was the dog.
    Dan likes this.
  5. tyteen4a03

    tyteen4a03 Well-Known Member

    If you come from JavaScript or Lua it's easy to make that mistake.
  6. Marcel

    Marcel Active Member

    I come from 20 years of being a nerd but never actually getting off my backside and learning to code properly :D
    This is all new to me. New into PHP (Well, anything beyond building a simple website with borrowed bits of code here and there without understanding how they do what they do). :)

    Im still blaming the dog. :p
    tyteen4a03 likes this.

Share This Page