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

Setting up a simple page and using a query

Brent W

Well-known member
#1
I want to create a page called members.php. Within that page I want to use a simple SQL query. What is the easiest way to do this? What all would I need to call within members.php to be able to query the database?
 

Lawrence

Well-known member
#6
I use Pages for a lot of different things, and each of my Pages requires data stored in the DB and as well to write data back to the database. In the Edit Page screen I use a PHP callback to handle the queries (for public facing data), for example: IcewindDaleRP_IcewindDale_PageCallback_Shop::shopServices
PHP:
class IcewindDaleRP_IcewindDale_PageCallback_Shop
{
    public static function shopServices(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract $response)
    {
        $visitor = XenForo_Visitor::getInstance()->toArray();
        $shopsModel = XenForo_Model::create('IcewindDaleRP_IcewindDale_Model_Shops');
       
more code...

        $shopItems = $shopsModel->getAllItemsByShopId($criteria, $itemsPerPage, $sortBy);
               
        $response->params['adventurer'] = $visitor;
        $response->params['items'] = $shopItems;
        $response->params['shop_id'] = $shopId;
        $response->templateName = 'iwd_shop';
    }
Then I use Controller Public to handle any requests:

PHP:
class IcewindDaleRP_IcewindDale_ControllerPublic_Inventory extends XenForo_ControllerPublic_Abstract
{
    public function actionItemInfo()
    {
        $itemId = $this->_input->filterSingle('item_id', XenForo_Input::UINT);
        $charId = $this->_input->filterSingle('char_id', XenForo_Input::UINT);
           
        $visitorId = XenForo_Visitor::getUserId();
        if ($visitorId != $charId)
        {
            throw $this->responseException($this->responseError(new XenForo_Phrase(
                'iwd_cheaters_dont_prosper'), 404)
            );
        }
        $item = $this->_getShopsModel()->getShopItemById($itemId);

        more code...
       
        $viewParams = array(
            'user_id' => $charId,
            'item' => $item
        );
        return $this->responseView(
            'IcewindDaleRP_IcewindDale_ViewPublic_Iwd_Char_Record_Item_Info',
             'iwd_char_record_item_info',
             $viewParams
        );
    }