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

how i can get $resource.resource_id ?

Discussion in 'XenForo Development Discussions' started by TBDragon, Feb 21, 2014.

  1. TBDragon

    TBDragon Active Member

    hi

    i want to get the $resource.resource_id and use it in my own template with callback

    the template will be shown in the RM (i use Widget Framework and place the template in hook:resource_view_sidebar_below_resource_controls ) where i need to pass the $resource.resource_id to the call back

    like this

    HTML:
    <xen:callback class="TBDragon_RMEpisodes_index" method="getRM" params="$resource.resource_id"></xen:callback>
    and this is my index.php

    PHP:
    public static function getRM ($resource_id){

    $db XenForo_Application::get('db');

    //$resource_id = 1;
    $resource_category_id $db->fetchAll('
                                                    Select resource_category_id
                                                    from xf_resource
                                                    where resource_id =  ?
                                                    '
                                                    
    $resource_id);

    var_dump($resource_category_id);
    //$resource_category_id = '1';
    $AllRresource $db->fetchAll('
                                                    Select resource_id,title
                                                    from xf_resource
                                                    where resource_category_id =  ?
                                                    '
                                                    
    ,$resource_category_id[0]);

    var_dump($AllRresource);
    print_r($AllRresource);


    }

    the code work fine without parameters for the method
     
  2. TBDragon

    TBDragon Active Member

    i use php function (basename)

    PHP:
    $resource_id basename($_SERVER['REQUEST_URI']).PHP_EOL;
    but i wana see if there is another way through XF it self
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    Yeah you need to format your PHP callback tag like this:
    HTML:
    <xen:callback class="TBDragon_RMEpisodes_index" method="getRM" params="$resource"></xen:callback>
    And your PHP like this:
    PHP:
    <?php

    class TBDragon_RMEpisodes_index
    {
        public static function 
    getRM($content$paramsXenForo_Template_Abstract $template)
        {
            
    $resource_id $params['resource_id'];
        }
    }
     
    TBDragon likes this.
  4. TBDragon

    TBDragon Active Member

    aaah now i see thats great

    sorry for that as i search for any thread talk about callback tag but didnt find something with params

    ^_^ thanks again i will try it now ^_^
     
  5. TBDragon

    TBDragon Active Member


    i got this error


    1. Illegal string offset 'resource_id' in C:\wamp\www\xen\library\TBDragon\RMEpisodes\index.php, line 10

    line 10 is
    $resource_id = $params['resource_id'];
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Is the $resource array available to the template in which you are using the callback?
     
    TBDragon likes this.
  7. TBDragon

    TBDragon Active Member

    no

    the template called getRm

    and its only have the callback code !!
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    What template have you put this code in?
    Code:
    <xen:callback class="TBDragon_RMEpisodes_index" method="getRM" params="$resource"></xen:callback>
     
    TBDragon likes this.
  9. TBDragon

    TBDragon Active Member

    i use Widget Framework
    to make a new Widget and this is the setting for that

    upload_2014-2-22_2-29-18.png

    and this is the template

    upload_2014-2-22_2-29-55.png


    and here its shows in the RM

    upload_2014-2-22_2-30-49.png

    its says empty as the error i tell u about


    i hope i give u every thing need and thanks for help
     
  10. TBDragon

    TBDragon Active Member

  11. Chris D

    Chris D XenForo Developer Staff Member

    It's unlikely that the $resource parameter is available when calling that in a widget renderer though xfrocks may be able to confirm.

    Maybe you should use a template modification to inject your code into that template.
     
  12. TBDragon

    TBDragon Active Member

    btw i put the callback tag in " resource_view " template

    and got slimier error
    Template Errors: resource_view
    1. Illegal string offset 'resource_id' in C:\wamp\www\xen\library\TBDragon\RMEpisodes\index.php, line 10:
      9: ';
      10: $__compilerVar40 = '';
      11: $__output .= $this->callTemplateCallback('TBDragon_RMEpisodes_index', 'getRM', $__compilerVar40, '$resource');
     
  13. TBDragon

    TBDragon Active Member

    any help ?!
     

Share This Page