The Repository folder

Started Start date Start date - by Thread starter Thread starter Milen and have 0 Replies and 55 Views
Tags Tags
add-ons folders xenforo

Milen

Owner
Staff member
Admin
Messages
98
Reaction score
15
Points
8
Credits
119
Maybe this is where we should start before creating any add-on for XenForo, but each in their own way. Here I will try to collect information about what each folder in the Xenforo add-ons is for, if I have missed any, please share.

What is the Repository folder for in xenforo add-ons?​

XenBg-big.jpg
In XenForo, the Repository folder in the addons structure is typically used to store classes that contain the business logic or database interaction for a specific data type. This is part of the XenForo architectural model and helps organize the code.

  1. Database query management:
    • Classes in this folder often contain methods for retrieving, filtering, or modifying data from the database.
    • For example: retrieving a list of topics, users, or other objects.
  2. Centralization of business logic:
    • Instead of logic being scattered across different controllers, models, or other classes, it is centralized in Repository classes.
    • This makes code reuse easier and improves readability.
  3. Structure and standard:
    • XenForo encourages the use of Repository classes for data management to maintain a good coding standard.
    • This makes it easier to integrate new features and support add-ons.
If you are creating a news display plugin, you might have a class in the Repository that looks like this:
Code:
namespace YourAddon\Repository;

use XF\Mvc\Entity\Repository;

class News extends Repository
{
    public function getLatestNews($limit = 5)
    {
        return $this->finder('YourAddon:News')
            ->order('publish_date', 'DESC')
            ->limit($limit)
            ->fetch();
    }
}

Usage:​

This Repository class can be called from another class, for example a controller or cron job:
PHP:
$newsRepo = \XF::repository('YourAddon:News');
$latestNews = $newsRepo->getLatestNews(10);

The Repository folder in XenForo add-ons is used to organize the code that deals with data management and business logic. It makes it easier to work with the database, centralize logic, and maintain add-ons.
 

More for you :)

What is <xf:if for and how can it be used?
In XenForo 2 , <xf:if> is a conditional template tag that is used to check a condition in XenForo templates. It allows for dynamically showing or...
by Milen in XenForo 2 AddOns

Thread statistics

Created
Milen,
Replies
0
Views
55

New threads

Hot

[XenBg] Portal
Day 1 I've been stubborn about making a portal anyway :D Why not start? After a lot of really hard work, I managed to get the forum to show some...
by Milen in Working on
Daily moon calendar
When we live in accordance with the lunar calendar, we begin to feel the natural rhythms that influence us and we can ride the energy wave, like a...
by Milen in Moon Calendar
[XenBg] Portal Pro [Addons]
[XenBg] Portal thread for updates and discussion. If you see this in the Last repli widget, there is likely a new update. You can take a look to...
by Milen in AddOn releases
XenBg Pro Style
Perhaps every person who owns any kind of website (whether it's a forum or a blog, it doesn't matter) has had a moment when they saw something and...
by Milen in Working on
Xenforo seo
! It's important google search engine to like your forum ! Day 1 Working on this addon is starting at 27.01.2025. I've been a webmaster for a...
by Milen in Working on
Back
Top