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

Help pls with data-loadUrl

Discussion in 'XenForo Development Discussions' started by ragtek, Dec 29, 2010.

  1. ragtek

    ragtek Guest

    I'm working on the next version of http://xenforo.com/community/threads/ragtek-registration-statistics.9689/

    I have 2 tabs.
    [​IMG]

    Code:
    <ul id="ragtektabs" class="Tabs tabs" data-panes="#ragtek > li">
        <li>
            <a href="admin.php?users/RegistrationStats">daily Stats</a>
        </li>
        <li>
            <a href="admin.php?users/RegistrationStatsmonthly">monthly stats</a>
        </li>
    </ul>
    <ul id="ragtek">
        <li id="daily">
            <table class="dataTable" id="stats">
                <thead>
                <tr>
                    <th>{xen:phrase date}</th>
                    <th>{xen:phrase stats_registrations}</th>
                </tr>
                </thead>
                <tbody>
                <xen:foreach loop="$stats" value="$stat">
                    <tr>
                        <td>{xen:date $stat.date, 'M.Y'}</td>
                        <td>{$stat.registrations}</td>
                    </tr>
                </xen:foreach>
                </tbody>
            </table>
        </li>
    <li id="monthly" data-loadUrl="admin.php?users/RegistrationStatsmonthly">
    ..content.. will be replaced with ajax data
    </li>
    </ul>
    my controller object:
    PHP:
        private function getView($stats)
        {
            
    $viewParams = array(
                
    'stats' => $stats
            
    );

            return 
    $this->responseView('Ragtek_RS_ViewAdmin''ragtek_user_registrationstats'$viewParams);
        }
    My view object:
    PHP:
    class Ragtek_RS_ViewAdmin extends XenForo_ViewAdmin_Base{

        public function 
    renderJson()
        {
            return 
    XenForo_ViewRenderer_Json::jsonEncodeForOutput(array(
                    
    'templateHtml' => 'test'));
        }
    }
    With firebug i can see, that the response contains json data, but there is no content under the tab. (normalery there would be test) or?


    (Sorry for my english, i hope you can understand it^^)
     
  2. Shadab

    Shadab Well-Known Member

    You need to return a proper html string. Try...
    PHP:
    array('templateHtml' => '<p>Test</p>')
    As it stands, the content which you return gets passed to $(), ie jQuery. If it doesn't look like a proper html snippet, jQuery will use it as a selector: $('test'), so it would now look for an existing tag named <test> and try to load its content in the tab pane! (Return h1 instead of test and see what happens) [​IMG]

    http://api.jquery.com/jQuery/

    This might not be classed as a bug, I'm not sure. But it can be annoying when returning plain text for debugging purposes; for example, via responseMessage().
     
    1 person likes this.
  3. ragtek

    ragtek Guest

    oh man:(

    if i had tried it with an template, instead of my f*cking "test" string, it would be finished allready:D
    grrrrr

    thx shadab for all the help!:)
     
    Shadab likes this.
  4. ragtek

    ragtek Guest

    I had to create my own view Object for this, which renders the json data.
    That's now my code:
    PHP:
       public function renderJson()
        {
            
    $this->_templateName 'ragtek_registrationstats_table';
            
    $output $this->_renderer->getDefaultOutputArray(get_class($this), $this->_params$this->_templateName);

            return 
    XenForo_ViewRenderer_Json::jsonEncodeForOutput($output);
        }

    Maybe it's usefull to somebody^^
     
  5. Shadab

    Shadab Well-Known Member

    Actually you shouldn't need to do that explicitly. (Not even create a View class).
    Just specifying the view name, template and parameters in your controller is enough.

    PHP:
    return $this->responseView('Pseudo_View_Class_Name''ragtek_registrationstats_table'$viewParams);
    The JSON view render does the job of rendering the template and encoding the output params.
     
    1 person likes this.
  6. ragtek

    ragtek Guest

    you're right.
    It's working without the view class

    thx:)
     

Share This Page