how i can get $resource.resource_id ?

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
 
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
 
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, $params, XenForo_Template_Abstract $template)
    {
        $resource_id = $params['resource_id'];
    }
}
 
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 ^_^
 
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, $params, XenForo_Template_Abstract $template)
    {
        $resource_id = $params['resource_id'];
    }
}


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'];
 
What template have you put this code in?
Code:
<xen:callback class="TBDragon_RMEpisodes_index" method="getRM" params="$resource"></xen:callback>
 
i use Widget Framework
to make a new Widget and this is the setting for that

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

and this is the template

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


and here its shows in the RM

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

its says empty as the error i tell u about


i hope i give u every thing need and thanks for help
 
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.
 
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.

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');
 
Top Bottom