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

container_public_params

Mythotical

Well-known member
#1
Ok, after much reading I have discovered the use of this listener. The problem I run into is that I need to call models and pass information so it can be displayed within a linksTemplate.

I'm trying this:
PHP:
public static function params(array &$params, XenForo_Dependencies_Abstract $dependencies)
        {
            // Build the Model for caching
        $feedModel = $this->getModelFromCache('NewsReader_Model_Feed');
        
        // Unique for testing only.
        $visitor = XenForo_Visitor::getInstance();
        $visitor_id = $visitor->getUserId();
        $userName = $visitor['username'];
        
        // Lets paginate the results
        $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
        $perPage = $options->nr_limit;
        $allFeeds = $feedModel->getPrefixFeedLog(array('perPage' => $perPage, 'page' => $page), $prefixId);
        $count = $feedModel->getPrefixFeedAllCount($prefixId);
        
            $params = array(
                'allFeeds' => $allFeeds,
                'count' => $count
            );
        }
Now as I have found out $this is not allowed. Is there a way around it? If I have to use another method then I'm open to suggestions, just give me an example run down of setting it up.

Thanks
 

Mythotical

Well-known member
#2
Ok I figured that out, here is the new errors:
Code:
[SIZE=3][B]Template Errors: nr_links[/B][/SIZE]

[LIST=1]
[*][I]Non-static method NewsReader_Model_Prefix::getPrefix() should not be called statically[/I]in /home/area51/public_html/xenforo/library/NewsReader/Listener/Vars.php, line 16:
15: $__output .= $this->callTemplateHook('nr_links_end', $__compilerVar1, array());
16: unset($__compilerVar1);
17: $__output .= '
[*][I]Argument 1 passed to NewsReader_Model_Prefix::getPrefix() must be an array, none given, called in /home/area51/public_html/xenforo/library/NewsReader/Listener/Vars.php on line 16 and defined[/I]in /home/area51/public_html/xenforo/library/NewsReader/Model/Prefix.php, line 4:
3: ';
4: $__compilerVar1 = '';
5: $__compilerVar1 .= '
[*][I]Missing argument 1 for NewsReader_Model_Prefix::getPrefix(), called in /home/area51/public_html/xenforo/library/NewsReader/Listener/Vars.php on line 16 and defined[/I]in /home/area51/public_html/xenforo/library/NewsReader/Model/Prefix.php, line 4:
3: ';
4: $__compilerVar1 = '';
5: $__compilerVar1 .= '
[*][I]Non-static method NewsReader_Model_Prefix::getAllCount() should not be called statically[/I]in /home/area51/public_html/xenforo/library/NewsReader/Listener/Vars.php, line 17:
16: unset($__compilerVar1);
17: $__output .= '
18: </ul>';
[/LIST]
Here is my Prefix.php model:
PHP:
<?php 
class NewsReader_Model_Prefix extends XenForo_Model
{
    public function getPrefix(array $fetchOptions)
    {
        $options = XenForo_Application::get('options');
        
        
        return XenForo_Application::get('db')->fetchAll('
            SELECT * FROM `xf_thread_prefix`
            ');

    }
    public function getAllCount()
    {
        return XenForo_Application::get('db')->fetchOne('SELECT COUNT(*)
        FROM `xf_thread_prefix`');
    }
}
?>
 

Jake Bunce

XenForo moderator
Staff member
#3
If you want to call those functions statically then you need to use "public static function" instead of "public function". Otherwise you need to instantiate your prefix model before calling those functions.
 

Mythotical

Well-known member
#5
Ok that worked, I have ran into another problem, I am building the link properly, but for some reason the id isn't passing to the next page. Not sure what I did wrong but here is my index page:
PHP:
<?php
class NewsReader_ControllerPublic_Index_Prefix extends XenForo_ControllerPublic_Abstract
{
    public function actionIndex()
    {
        // Prepare to grab any options needed
        $options = XenForo_Application::get('options');
        
        $pageId = $this->_input->filterSingle('prefix_id', XenForo_Input::UINT);
        //$page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
        //$perPage = $options->nr_limit;
        
        $pageE = $this->_getContentModel()->getPrefixFeedLog($pageId);
        if (!$pageE)
        {
            throw $this->responseException($this->responseError(new XenForo_Phrase('requested_page_not_found'), 404));

        }
        // Build the public link
        $this->canonicalizeRequestUrl(
            XenForo_Link::buildPublicLink('news/prefix', $pageId)
        );
        
        var_dump($pageId);
        
        // Unique for testing only.
        $visitor = XenForo_Visitor::getInstance();
        $visitor_id = $visitor->getUserId();
        $userName = $visitor['username'];
        
        // Lets paginate the results
        
        
        $feed = array();
        foreach ($pageE AS $feeds)
        {
            $prefix = new XenForo_Phrase('thread_prefix_' . $feeds['prefix_id']);
            if (!$feeds['prefix_id'])
            {
            $feed[] = '<li style="border-bottom:1px solid #cecfd0;padding-left:3px;line-height:20px;"><a href="javascript:frameSrc(\''. $feeds['unique_id'].'\'); var waste = \'/threads/\';">'. $feeds['title'] .'</a><span style="float:right;"><a href="threads/'. $feeds['thread_id'] .'/reply">Comment</a></span></li>';
            } else {
            $feed[] = '<li style="border-bottom:1px solid #cecfd0;padding-left:3px;line-height:20px;">['.$prefix.'] <a href="javascript:frameSrc(\''. $feeds['unique_id'].'\'); var waste = \'/threads/\';">'. $feeds['title'] .'</a><span style="float:right;"><a href="threads/'. $feeds['thread_id'] .'/reply">Comment</a></span></li>';
            }
        }
        
        // Register for use in the template
        $viewParams = array(
            //'page' => $page,
            //'perPage' => $perPage,
            'username' => $userName,
            'visitor_id' => $visitor_id,
            //'feeds' => $allFeeds,
            //'prefixGroup' => $prefixGroup,
            'prefix' => $prefix,
            //'data' => $data,
            'feed' => $feed,
            'feeds' => $feeds,
        );

        return $this->responseView('NewsReader_ViewPublic_News', 'nr_index_prefix', $viewParams);
    }

    protected function _getContentModel()
    {
        return $this->getModelFromCache('NewsReader_Model_Feed');
    }
}
?>
This is my template that holds the link with the variable I need to pass:
HTML:
<ul class="secondaryContent blockLinksList">
<xen:foreach loop="$prefix" value="$p">
<li><a href="{xen:link 'news/prefix', $p}">{xen:helper threadPrefix, $p.prefix_id, escaped, ''}</a></li>
</xen:foreach>
</ul>
Lastly this is my model for gathering the information:
PHP:
    public function getPrefixFeedLog($pageId)
    {
        $options = XenForo_Application::get('options');
        
        
        return $this->_getDb()->fetchAll('
            SELECT log.*, thread.* FROM `xf_feed_log` AS `log`
            LEFT JOIN `xf_thread` AS `thread` ON (thread.thread_id = log.thread_id)
            WHERE thread.prefix_id = ?
            ', $pageId);

    }
 

Mythotical

Well-known member
#7
Exactly.

In my router I have it set for the intParam to be prefix_id and when using xen:link it shows correctly but won't pass that prefix_id.
 

Mythotical

Well-known member
#8
Also when I do var_dump($pageId); all it reports back is int(0) sooooo it has to be somewhere in the middle from the time I click the link to the load of the next page.
 

Jake Bunce

XenForo moderator
Staff member
#9
Try debugging this line to see if the value is being captured:

Code:
$pageId = $this->_input->filterSingle('prefix_id', XenForo_Input::UINT);
It's all a matter of debugging to track down the problem.
 

Mythotical

Well-known member
#11
Ok I did some debugging further and apparently it isn't getting passed. It is displaying in the main template but not passing to the prefix file.
 

Mythotical

Well-known member
#13
I'm officially waving the white flag. I have no idea why its not working, hate to start from the beginning but I may have to putting me weeks behind on this.
 

Mythotical

Well-known member
#14
Found the problem, I had this in my Prefix controller:
PHP:
// Build the public link
       $this->canonicalizeRequestUrl(
            XenForo_Link::buildPublicLink('news-prefix', $prefix_id, array('page' => $page))
        );
I do have to give thanks to bobster65 as he helped direct me towards the problem without knowing he did.