Get prefix_id of current thread

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

thread/1234/sold

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.
 
Have you dumped the param to see what's available?

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

In the template: {xen:helper dump, $thread}
 
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/
 
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.
 
  • Like
Reactions: Dan
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.
If you come from JavaScript or Lua it's easy to make that mistake.
 
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
 
Back
Top Bottom