XF 2.0 Regarding custom coding

Hello,
I am having a problem while fetching a data from my database table. When I used to fetch the data from user table, everything works fine, but when I tried to fetch the data from my custom table it given me an error.
My database table name: xf_schedule_match

The code that I have used in my file at path: src\addons\Site\Pages\CatFiftyTwo.php
PHP:
namespace Site\Pages;



class CatFiftyTwo

{

public static function getData(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)

{

if ($reply instanceof \XF\Mvc\Reply\View)

{

$finder = \XF::finder('XF:schedule_match');
$reply->setParam('catinfo', $finder->fetch());

}

}

}


but it gives me an error.

1593929856941.png

Please help me to resolve this issue? Is there something that need to be done if we are fetching data from a custom table?
 

Lukas W.

Well-known member
You should get started with the dev docs and the "how to build an add-on" section to learn how to properly use the finder system.
 
Hello,

Thanks for your kind reply
We just want to ask how do we need to fetch the data from our custom made table.
When we try to fetch the data from the user table it brings the data but when we try to fetch the data from the custom table, it gives an error. Do we have to define table name anywhere?
 
Here is the code I used for my testing:

PHP:
<?php

namespace Site\Pages;

class CatFiftyTwo
{
    public static function getData(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply)
    {
        if ($reply instanceof \XF\Mvc\Reply\View)
        {
            $finder = \XF::finder('XF:User')->where('user_id', '<', 100);
            $finder->order('username', 'ASC');
      
            $reply->setParam('catinfo', $finder->fetch());
        }
    }
}

Attached is my settings for the page node and navigation, and as well the screenshot of the resulting output:

View attachment 229630View attachment 229631View attachment 229632

@Chris D I inserted the attachments as thumbnails, these are pretty large thumbnails...
Hi,

we need to fetch the data from our custom made table.
When we try to fetch the data from the user table it brings the data but when we try to fetch the data from the custom table, it gives an error. Do we have to define table name anywhere?

Thank you
 

Lawrence

Well-known member
Hi,

we need to fetch the data from our custom made table.
When we try to fetch the data from the user table it brings the data but when we try to fetch the data from the custom table, it gives an error. Do we have to define table name anywhere?

Thank you

You should get started with the dev docs and the "how to build an add-on" section to learn how to properly use the finder system.

As @Lukas W. points out, you need to read the dev docs.

This is where I started to learn to create XF 2.x add-ons, it is an excellent tutorial: https://xenforo.com/xf2-docs/dev/lets-build-an-add-on/
 
Hello,
can you please let me know how can I put few logo at the top of the page from Admin?

1594455183718.png

I want to add logos at the top but it should be managed from the Admin. Now I have added it from the page :
internal_data\code_cache\templates\l1\s1\public\PAGE_CONTAINER.php

But everytime I make changes from the Admin this code disappears may be because this is cache page. So, how can I manage the Header section from the Admin?
 
As @Lukas W. points out, you need to read the dev docs.

This is where I started to learn to create XF 2.x add-ons, it is an excellent tutorial: https://xenforo.com/xf2-docs/dev/lets-build-an-add-on/
Hi Lawrence,

Do you have any solution for this

can you please let me know how can I put few logo at the top of the page from Admin?

1594455183718.png



I want to add logos at the top but it should be managed from the Admin. Now I have added it from the page :
internal_data\code_cache\templates\l1\s1\public\PAGE_CONTAINER.php

But everytime I make changes from the Admin this code disappears may be because this is cache page. So, how can I manage the Header section from the Admin?

Thank you
 

Lawrence

Well-known member
If you already know how to do this but want to know which template to edit in the AdminCP side of things, try the PAGE_CONTAINER template, and maybe put your code after the </li> (I got to play with it to be sure but graphics layouts are not my cup of tea):

HTML:
                    <xf:foreach loop="$navTree" key="$navSection" value="$navEntry" i="$i" if="{{ $navSection != $xf.app.defaultNavigationId }}">
                        <li>
                            <xf:macro name="nav_entry"
                                arg-navId="{$navSection}"
                                arg-nav="{$navEntry}"
                                arg-selected="{{ $navSection == $pageSection }}"
                                arg-shortcut="{$i}" />
                        </li>
                    </xf:foreach>
 
Hello,
But the problem is that whatever we make the changes in PAGE_CONTAINER template it removes itself whenever we change anything from Admin.
May be because this is cache page?
 

Lawrence

Well-known member
AdminCP -> Appearance -> Templates -> select your style from the drop down -> PAGE_CONTAINER Making changes here will stick, even during upgrades. The only time changes will be lost is if you manually select to Revert the template.
 
AdminCP -> Appearance -> Templates -> select your style from the drop down -> PAGE_CONTAINER Making changes here will stick, even during upgrades. The only time changes will be lost is if you manually select to Revert the template.
Hi Lawrence,

Thanks for your reply
we tried to put the code on the file which you suggested but it didn't appear at the front, moreover, it's not clear that how it will be managed from the Admin.

Thank you
 
Hello,

Below is my home page



1594803242420.png

in above screenshot there are 10 logos at the top which I want to managed by Admin dynamically.
for now I have put a status code on following path:
internal_data\code_cache\templates\l1\s1\public\PAGE_CONTAINER.php

I tried to put the code in admin Panel in below template, but I am not sure how to make it dynamic?



1594803534432.png
 

Attachments

  • 1594803207856.png
    1594803207856.png
    681.6 KB · Views: 2

Lawrence

Well-known member
Good day, if you want to have the logos managed it will need to be done through an add-on.

If you are already making this add-on, to achieve what you want the add-on will have to:
  • create a template modification to add the logos to the navigation section of the PAGE_CONTAINER template
  • create a section in the AdminCP that will allow admins to upload (logo) images, and manage them (active, inactive, delete, display order, etc), and make them accessible to the template modification via a query.
If you are already doing this, and have specific questions as to why something is not happening as expected, then you can post them here and members will be happy to help out. If you are not in the process of creating one, you can request to have one made here or here.
 
Hello,
yes we tried to create new page in Admin to manage few things, but can you please let us know that how and from where do we need to create those pages?
And how those pages will be called from Admin panel only after logging into the Admin
 
Top