Pulling a function into a template

Gossamer

Active member
Hello! So, I'm tackling another modification for my forum. I followed the tutorial on reading and writing to the database here, and it was very helpful. I've modified the end result a bit to include two fields that end up getting compiled into a list. I also removed the page element and instead used a new route prefix to create the main page for this modification.

The tutorial has it setup so that the "write" is on one tab and the "read" is on a second tab. I'm trying to get the contents of both to display in one view without the tabs. Unfortunately, I haven't figured out how to do so and still keep the functionality of the "read" tab, which is passed via a link.

What's a method to pull in functionality into a template? So far, I've only done it through page callbacks or template hooks and I'm having trouble finding an alternative to those.

Here is my ControllerPublic file:
PHP:
<?php

class goss_Reservations_ControllerPublic_Reserves extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {
        return $this->responseView('Reservations_ViewPublic_Reserves', 'goss_reserves');
    }
   
    /**
    * Write to the database the text that the user wrote in the textbox.
    */
    public function actionWrite()
    {
        //Get the text that user wrote in the text box
    /*    $Character = $this->_input->filterSingle('Character', XenForo_Input::STRING); */
        $Reserve = $this->_input->filter(array(
            'Character' => XenForo_Input::STRING,
            'Fandom' => XenForo_Input::STRING));
    
        //Create a instance of our DataWriter
        $dwReserve = XenForo_DataWriter::create('Goss_Reservations_DataWriter_Reserves');
    
        //Set the field with the data we filtered
        $dwReserve->bulkSet($Reserve);
    
        //Save in the database, please!
        $dwReserve->save();
    
        //Send a response to the user, so he know that everything went fine with this action
        return $this->responseRedirect(
                    XenForo_ControllerResponse_Redirect::SUCCESS,
                    $this->getDynamicRedirect()
                );
    }
   
    /**
    * Get all the saved text in our table.
    */
    public function actionRead()
    {
        //Get all rows from our table and set it to a variable
        $viewParams = array('Reserves' => $this->_getReserveModel()->getAllReserves());
    
        //Send a response view, using a template, to show all the data that we get it.
        return $this->responseView('XenForo_ViewPublic_Base', 'goss_reserves_list', $viewParams);
    
    }
   
    /**
    * Get the simple text model.
    *
    * @return SimpleText_Model_SimpleText
    */
    protected function _getReserveModel()
    {
        return $this->getModelFromCache ( 'Goss_Reservations_Model_Reserves' );
    }
   
}

And this is how the "read" view is currently pulled in through a template:
PHP:
<li id="read" class="profileContent" data-loadUrl="{xen:link reserves/read}">
<span class="jsOnly">{xen:phrase loading}...</span>
</li>

Any help would be greatly appreciated. I can show the rest of my code too if necessary.
 
I currently have this:

One tab ("Write") that collects two fields (character and fandom) into a new table in the database.
2w2r1aq.jpg


A second tab ("Read") that currently lists Character, Fandom, and OriginalDate of all rows from that new table in the database.
rbwtvt.jpg


I built this based off of the "How to read and write into the database (with a page)" tutorial. Only differences I made so far is that there is no page involved (I created a new page using the route prefix instead), it uses two templates instead of one, and it collects two fields instead of one.

I want those two functions (write and read) to be on the same page. I don't want them separated by tabs. I'm not sure how to go about doing that with the current setup I have based off of the tutorial.

I've attached my WIP add-on in case that helps.
 

Attachments

Replace
PHP:
public function actionIndex()
{
    return $this->responseView('Reservations_ViewPublic_Reserves', 'goss_reserves');
}
with
PHP:
public function actionIndex()
{
    //Get all rows from our table and set it to a variable
    $viewParams = array('Reserves' => $this->_getReserveModel()->getAllReserves());
    
    return $this->responseView('Reservations_ViewPublic_Reserves', 'goss_reserves', $viewParams);
}

Move the contents of goss_reserves_list into goss_reserves. All done.
 
Top Bottom