SneakyDave
Well-known member
EDIT: No, I just misinterpreted the first line.
I haven't had to do much development with models until recently, so again, excuse the ignorance.
Anyway, this is a piece of code that I was looking at, the easiest way to implement a model into an addon, This bit of code is from WidgetFramework, but it appears to be pretty consistent across other addons. This is from the WidgetRenderer that shows the latest ProfilePosts.
Code:
$core = WidgetFramework_Core::getInstance();
$visitor = XenForo_Visitor::getInstance();
$profilePostModel = $core->getModelFromCache('XenForo_Model_ProfilePost');
$profilePosts = $profilePostModel->WidgetFramework_getLatestProfilePosts(array(
'deleted' => false,
'moderated' => false
), array(
'limit' => $widget['options']['limit'] * 3,
'join' => XenForo_Model_ProfilePost::FETCH_USER_POSTER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER | XenForo_Model_ProfilePost::FETCH_USER_RECEIVER_PRIVACY,
'permissionCombinationId' => $visitor->permission_combination_id
));
The first 3 lines are no biggie, they are simple enough to understand.
The fifth line is what goes and executes the SQL from _getLatestProfilePosts method. But the method name appears to me like it shouldn't exist, WidgetFramework_getLatestProfilePosts()? Shouldn't it be the private _getLatestProfilePosts() method from the XenForo_Model_ProfilePost class?
When the $profilePostModel object is instantiated, how can WidgetFramework methods be available if it's a native XenForo ProfilePost model?
Am I missing something? Isn't the $profilePostModel->WidgetFramework_getLatestProfilePosts() statement calling a method from the $profilePostModel object?
OK, the other question, and maybe I don't even want to ask it, is that I've seen a lot of constants, like the ones used on line 5, like the FETCH_USER_ constants.
Code:
const FETCH_USER_POSTER = 0x01;
What are these hex values used for, why are they hex? Are they just binary representations of a column on a table?
Ok, that's it, thanks in advance for any help. I'll keep digging and seeing if I can interpret what's going on.
Last edited: