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

questions on [part 3] Creating a add-on to insert tabs in profile page (using hooks)

#1
I am reading [part 3] Creating a add-on to insert tabs in profile page (using hooks):
http://xenforo.com/community/thread...nsert-tabs-in-profile-page-using-hooks.21289/

I got serveral questions,


1. Step 5 - Extending the Controller Public - Member

Code:
...
$userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
...
Question:
user_id is the field in table:xf_user, right? but here it did not connect to DB, how could it get the value of user_id?

2. Step 5 - Extending the Controller Public - Member

Code:
...
return $this->responseView(
            'newProfileTab_ViewPublic_Member_UsersLike', 'newProfileTab_ourTab_content',
array('user' => $user, 'users_likes' => $users_likes)
...
Question:
Is 'newProfileTab_ViewPublic_Member_UsersLike' a view class? where is the declaration of it?


3. Step 7 - Changing our template content

Code:
...
data-loadUrl="{xen:link members/userslike, $user}
...
Question:
where can I check the usage of data-loadUrl?

4. Step 7 - Changing our template content

Code:
...
<xen:foreach loop="$users_likes" value="$like">
...
Question:
How to use foreach in XenForo?

5. Step 7 - Changing our template content

Code:
...
{xen:helper snippet, $like.message, 150}
...
Question:
how to use xen:helper? Is any documentation about it?
 

tyteen4a03

Well-known member
#2
1. Step 5 - Extending the Controller Public - Member

Code:
...
$userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
...
Question:
user_id is the field in table:xf_user, right? but here it did not connect to DB, how could it get the value of user_id?
This is passed from a form. $this->_input is an instance of XenForo_Input, which is used for form filtering.

2. Step 5 - Extending the Controller Public - Member

Code:
...
return $this->responseView(
            'newProfileTab_ViewPublic_Member_UsersLike', 'newProfileTab_ourTab_content',
array('user' => $user, 'users_likes' => $users_likes)
...
Question:
Is 'newProfileTab_ViewPublic_Member_UsersLike' a view class? where is the declaration of it?
Correct. For responseView calls, this class does not have to exist unless you need to override some built-in functionality (e.g when you need to output XML/JSON instead of HTML)

3. Step 7 - Changing our template content

Code:
...
data-loadUrl="{xen:link members/userslike, $user}
...
Question:
where can I check the usage of data-loadUrl?
Search for loadurl in the javascript. The data- prefix hints that it is custom-defined.

4. Step 7 - Changing our template content

Code:
...
<xen:foreach loop="$users_likes" value="$like">
...
Question:
How to use foreach in XenForo?
Code:
<xen:foreach loop="$users_likes" value="$like">
Is the same as
Code:
foreach ($users_likes as $like)
5. Step 7 - Changing our template content

Code:
...
{xen:helper snippet, $like.message, 150}
...
Question:
how to use xen:helper? Is any documentation about it?
Usage is:
{xen:helper helperName, argument1, argument2, argument3...}

For a list of helpers, consult the classes under XenForo_Template_Helper.
 
#4
when I review this tutorial: [part 3] Creating a add-on to insert tabs in profile page (using hooks):
http://xenforo.com/community/thread...nsert-tabs-in-profile-page-using-hooks.21289/,
I got some other questions:

Step 5 - Extending the Controller Public - Member
1.
Code:
class newProfileTabs_Extend_ControllerPublic_Member extends XFCP_newProfileTabs_Extend_ControllerPublic_Member
although it mentioned:
this is the XenForo Class Proxy system (XFCP), that "allows the system to effectively have multiple inheritance capabilities"
,i still did not get it, it seems extend itself, so what inheritance it can get? can anyone give me more info about it?


2.
Code:
$userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
I know from tyteen4a03 :
This is passed from a form. $this->_input is an instance of XenForo_Input, which is used for form filtering.
But in template:newProfileTab_ourTab_content, there is no form or input field, such as:
Code:
<input type="text" name="user_id">
,
so where is the value of user_id from?


3.
Code:
$user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId);
$users_likes =$this->getModelFromCache('newProfileTabs_Model_newProfileModel')->getAllGivenLikesByUser($userId, '10');
getHelper and getModelFromCache are methods in library\XenForo\Controller.php,
how could this class (class newProfileTabs_Extend_ControllerPublic_Member extends XFCP_newProfileTabs_Extend_ControllerPublic_Member)
access the methods in library\XenForo\Controller.php?

4.
Code:
 return $this->responseView(
  'newProfileTab_ViewPublic_Member_UsersLike', 'newProfileTab_ourTab_content',
array('user' => $user, 'users_likes' => $users_likes)
  );
In frontend, I want to see what is inside $user? so i put {$user} in template: newProfileTab_ourTab_content, but in frontend, it shows:
htmlspecialchars() expects parameter 1 to be string...but if i put {$user.username}, it shows correctly:admin, so if I want to see the content in $user, what should I do?
 

tyteen4a03

Well-known member
#5
when I review this tutorial: [part 3] Creating a add-on to insert tabs in profile page (using hooks):
http://xenforo.com/community/thread...nsert-tabs-in-profile-page-using-hooks.21289/,
I got some other questions:

Step 5 - Extending the Controller Public - Member
1.
Code:
class newProfileTabs_Extend_ControllerPublic_Member extends XFCP_newProfileTabs_Extend_ControllerPublic_Member
although it mentioned: ,i still did not get it, it seems extend itself, so what inheritance it can get? can anyone give me more info about it?
Using Proxy Classes (the XFCP prefix) allows multiple classes to extend the same class without conflicts. I can type a more detailed explanation if you'd like (the concept is really simple, but a lot of code examples are needed to support my post. Might as well write a full-fledged tut :))

2.
Code:
$userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
I know from tyteen4a03 :
But in template:newProfileTab_ourTab_content, there is no form or input field, such as:
Code:
<input type="text" name="user_id">
,
so where is the value of user_id from?
This user_id is fed from the router class. In this case, XenForo_Route_Prefix_Members. An in-depth (but will make you dizzy) tutorial is here: http://xenforo.com/community/resources/creating-a-proper-route-controller.1637/

3.
Code:
$user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId);
$users_likes =$this->getModelFromCache('newProfileTabs_Model_newProfileModel')->getAllGivenLikesByUser($userId, '10');
getHelper and getModelFromCache are methods in library\XenForo\Controller.php,
how could this class (class newProfileTabs_Extend_ControllerPublic_Member extends XFCP_newProfileTabs_Extend_ControllerPublic_Member)
access the methods in library\XenForo\Controller.php?
Class inheritance: newProfileTabs_Extend_ControllerPublic_Member extends XFCP_newProfileTabs_Extend_ControllerPublic_Member (fakeClass), actually extends XenForo_ControllerPublic_Member extends XenForo_ControllerPublic_Abstract extends XenForo_Controller. You're probably stuck at the proxy class bit, but after that it's pretty straightforward - just follow the codes.

4.
Code:
 return $this->responseView(
  'newProfileTab_ViewPublic_Member_UsersLike', 'newProfileTab_ourTab_content',
array('user' => $user, 'users_likes' => $users_likes)
  );
In frontend, I want to see what is inside $user? so i put {$user} in template: newProfileTab_ourTab_content, but in frontend, it shows:
htmlspecialchars() expects parameter 1 to be string...but if i put {$user.username}, it shows correctly:admin, so if I want to see the content in $user, what should I do?
$user in most cases stands for a standard user array.

In the Controller, just do a var_dump() on where the $user is fed from.

In the Template, use the dump template helper: {xen:helper dump, $user}
 
#6
tyteen4a03, Thanks, your answers are very helpful!
I have two more questions about it.
1.
3. Step 7 - Changing our template content


Code:
... data-loadUrl="{xen:link members/userslike, $user} ... Question:
where can I check the usage of data-loadUrl? Search for loadurl in the javascript. The data- prefix hints that it is custom-defined.
how to search it in javascript?in frontend, it shows:
Code:
data-loadurl="members/admin.1/userslike"
,
so a: what is the purpose to use data-loadUrl? b: how does xen:link work?


2. Step 7 - Changing our template content
Code:
<xen:username user="{$like}" rich="true" />
I checked this file: XenForo\Template\Compiler\Tag\Username.php
Code:
class XenForo_Template_Compiler_Tag_Username implements XenForo_Template_Compiler_Tag_Interface
{
    /**
    * Compile the specified tag and return PHP code to handle it.
    *
    * @param XenForo_Template_Compiler The invoking compiler
    * @param string                Name of the tag called
    * @param array                  Attributes for the tag (may be empty)
    * @param array                  Nodes (tags/curlies/text) within this tag (may be empty)
    * @param array                  Compilation options
    *
    * @return string
    */
    public function compile(XenForo_Template_Compiler $compiler, $tag, array $attributes, array $children, array $options)
a. is $compiler=xen:?
b. user="{$like}" rich="true" in the array $attributes? if so, why not use this kind of format to pass these parameters: {user:$like, rich:"true"}? otherwise, how could we know parameter: user, rich, belongs to array $attributes or array $children?