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

Post thread from ViewPublic extending class

#1
Hello,

I just started developing add-ons for XenForo and I have a small question. I've been looking into the XenForo DataWriter class to write posts from my add-on but I need some kind of Forum class. Is there any way I can initialise a Forum class from the renderHtml environment in a ViewPublic extending class? Preferably something like $forum = SomeStaticIDontKnow::getForumModel($forumId)?

EDIT: I got lucky going through the source code and figured some stuff out. Would this work?
Code:
$forumId = 1;
$forumModel = XenForo_Model::create('XenForo_Model_Forum');
$forum = $forumModel->getForumById($forumId);
Example code of the simplest way to create a post in a forum would be much appreciated too :)

Also, is there developer documentation about all the classes analog to MSDN for the .NET framework?
 
Last edited:

Jeremy

Well-known member
#2
The _getXModel functions are defined per class and are usually short code for:
PHP:
XenForo_Model::create('XenForo_Model_Forum');
You may want to look into how XenForo posts threads to a specific forum. XenForo_ControllerPublic_Forum::actionAddThread(); contains the necessary logic.
 

Jeremy

Well-known member
#3
Yes, those actions correspond to the URL routes. However, you shouldn't be calling the controller action directly, you should just read it and learn how its doing that and write similar code in your add-on.

Create a thread is a POST action, you can see the data by inspecting the network as you create one.