PHP Joomla模板index.php JCategoryNode输出而不是当前类别ID号

时间:2017-02-21 19:26:50

标签: php joomla

因此,在我的主要Joomla模板/ index.php文件中,我正在执行以下操作以尝试获取用户当前正在查看的页面的类别ID号。

结果应为 9 ,因为这是类别的ID号

jimport('joomla.application.categories');
$category = JCategories::getInstance('hwdMediaShare')->get($this->item->categories[0]->id[0]);
print_r($category);
echo "\n\nCategory ID number is : ".($category)."\n\n";

我的var_dump显示了这一点(类别ID号9确实存在且存在于var转储中,因此我应该能够获取它)

[id] => 9
9:random

显示类别ID 9,其名称太“随机”

JCategoryNode Object ( [id] => root [asset_id] => 0 [parent_id] => 0 [lft] => 0 [rgt] => 21 [level] => 0 [extension] => system [title] => ROOT [alias] => root [description] => [published] => 1 [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [access] => 1 [params] => {} [metadesc] => [metakey] => [metadata] => {} [created_user_id] => 42 [created_time] => 2011-01-01 00:00:01 [modified_user_id] => 0 [modified_time] => 0000-00-00 00:00:00 [hits] => 0 [language] => * [numitems] => [childrennumitems] => [slug] => 1:root [assets] => [_parent:protected] => [_children:protected] => Array ( [0] => JCategoryNode Object ( [id] => 9 [asset_id] => 610 [parent_id] => root [lft] => 3 [rgt] => 4 [level] => 1 [extension] => com_hwdmediashare [title] => Random [alias] => random [description] => [published] => 1 [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [access] => 1 [params] => {"category_layout":"","image":""} [metadesc] => [metakey] => [metadata] => {"author":"","robots":""} [created_user_id] => 571 [created_time] => 2016-02-10 11:52:24 [modified_user_id] => 571 [modified_time] => 2016-03-16 15:45:36 [hits] => 1107 [language] => * [numitems] => [childrennumitems] => [slug] => 9:random [assets] => [_parent:protected] => JCategoryNode Object *RECURSION* [_children:protected] => Array ( ) [_path:protected] => Array ( [0] => 9:random ) [_leftSibling:protected] => [_rightSibling:protected] => [_allChildrenloaded:protected] => 1 [_constructor:protected] => hwdMediaShareCategories Object ( [_nodes:protected] => Array ( [root] => JCategoryNode Object *RECURSION* [9] => JCategoryNode Object *RECURSION* ) [_checkedCategories:protected] => Array ( [9] => 1 ) [_extension:protected] => com_hwdmediashare [_table:protected] => #__hwdms_category_map [_field:protected] => category_id [_key:protected] => id [_statefield:protected] => state [_options:protected] => Array ( [table] => #__hwdms_category_map [extension] => com_hwdmediashare [field] => category_id [published] => 0 [access] => true ) ) [_errors:protected] => Array ( ) [note] => [path] => uncategorised/test/uncategorised/random [version] => 1 ) ) [_path:protected] => Array ( ) [_leftSibling:protected] => [_rightSibling:protected] => [_allChildrenloaded:protected] => [_constructor:protected] => hwdMediaShareCategories Object ( [_nodes:protected] => Array ( [root] => JCategoryNode Object *RECURSION* [9] => JCategoryNode Object ( [id] => 9 [asset_id] => 610 [parent_id] => root [lft] => 3 [rgt] => 4 [level] => 1 [extension] => com_hwdmediashare [title] => Random [alias] => random [description] => [published] => 1 [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [access] => 1 [params] => {"category_layout":"","image":""} [metadesc] => [metakey] => [metadata] => {"author":"","robots":""} [created_user_id] => 571 [created_time] => 2016-02-10 11:52:24 [modified_user_id] => 571 [modified_time] => 2016-03-16 15:45:36 [hits] => 1107 [language] => * [numitems] => [childrennumitems] => [slug] => 9:random [assets] => [_parent:protected] => JCategoryNode Object *RECURSION* [_children:protected] => Array ( ) [_path:protected] => Array ( [0] => 9:random ) [_leftSibling:protected] => [_rightSibling:protected] => [_allChildrenloaded:protected] => 1 [_constructor:protected] => hwdMediaShareCategories Object *RECURSION* [_errors:protected] => Array ( ) [note] => [path] => uncategorised/test/uncategorised/random [version] => 1 ) ) [_checkedCategories:protected] => Array ( [9] => 1 ) [_extension:protected] => com_hwdmediashare [_table:protected] => #__hwdms_category_map [_field:protected] => category_id [_key:protected] => id [_statefield:protected] => state [_options:protected] => Array ( [table] => #__hwdms_category_map [extension] => com_hwdmediashare [field] => category_id [published] => 0 [access] => true ) ) [_errors:protected] => Array ( ) [note] => [path] => [version] => 1 ) Category ID number is : JCategoryNode

当我试图回显我的输出以查看我的号码时,我看到了这个

Category ID number is : JCategoryNode

任何人都可以在这里看到我做错了什么并纠正我。

应该说

Category ID number is : 9

0 个答案:

没有答案