1. 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

Discussion in 'XenForo Development Discussions' started by BamaStangGuy, Dec 20, 2013.

  1. BamaStangGuy

    BamaStangGuy Well-Known Member

    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?
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    What is the end goal of this file?
  3. ProCom

    ProCom Active Member

  4. AndyB

    AndyB Well-Known Member

    thedude likes this.
  5. BamaStangGuy

    BamaStangGuy Well-Known Member

    To handle vBSEO urls with no id in them and redirect to new url in xenForo.
  6. Lawrence

    Lawrence Well-Known Member

    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
    class IcewindDaleRP_IcewindDale_PageCallback_Shop
        public static function 
    shopServices(XenForo_ControllerPublic_Abstract $controllerXenForo_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:

    class IcewindDaleRP_IcewindDale_ControllerPublic_Inventory extends XenForo_ControllerPublic_Abstract
        public function 
    $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)
    $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
    thedude likes this.

Share This Page