• 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

Marcel

Active member
#1
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.
 

Brogan

XenForo moderator
Staff member
#2
Have you dumped the param to see what's available?

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

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

Marcel

Active member
#3
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/
 

Marcel

Active member
#4
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.
 

tyteen4a03

Well-known member
#5
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.
 

Marcel

Active member
#6
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