Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Meddysong Posted May 30, 2018 Posted May 30, 2018 In templates I see things like {$category->_title} and {$category->_description|raw} What I'd like to do is be able to find out for myself what properties different variables have. There might be some useful ones, but if I don't know about them, I can't use them. I seem to understand that the trick might be to use {{var_dump($variable);}} or {{var_export($variable);}} within the template but what displays isn't particularly readable. And when I do this for $category, there's certainly no mention of _title or _description in the output. I found something which produces a much more readable result: {{highlight_string("<?php\n\$category =\n" . var_export($category, true) . ";\n?>");}} But the result, again, doesn't actually include things that I'm looking for: <?php $category = IPS\cms\Categories36::__set_state(array( '_url' => IPS\Http\Url\Friendly::__set_state(array( 'base' => 'front', 'seoTemplate' => 'content_page_path', 'seoTitles' => array ( 0 => 'ready-willing-able', ), 'friendlyUrlComponent' => 'eab/people/ready-willing-able', 'isInternal' => true, 'isFriendly' => true, 'url' => 'https://xxx/eab/people/ready-willing-able/', 'data' => array ( 'scheme' => 'https', 'host' => 'xxx', 'port' => NULL, 'user' => NULL, 'pass' => NULL, 'path' => '/eab/people/ready-willing-able/', 'query' => '', 'fragment' => NULL, ), 'queryString' => array ( ), 'hiddenQueryString' => array ( 'app' => 'cms', 'module' => 'pages', 'controller' => 'page', 'path' => 'eab/people/ready-willing-able', ), )), '_catTitle' => NULL, '_catTitleLangKey' => NULL, '_lastCommentTime' => false, '_permsMashed' => true, '_updatePaths' => false, '_childrenResults' => array ( '9c6977b56dbfa37e0223c7ff8abd362e' => array ( ), ), '_permissions' => array ( 'perm_id' => 769, 'perm_view' => '*', 'perm_2' => '*', 'perm_3' => '4', 'perm_4' => '4', 'perm_5' => '', 'perm_6' => '4', 'perm_7' => '4', ), '_originalPermissions' => array ( 'perm_id' => 769, 'perm_view' => '*', 'perm_2' => '*', 'perm_3' => '4', 'perm_4' => '4', 'perm_5' => '', 'perm_6' => '4', 'perm_7' => '4', ), 'noCopyButton' => false, 'contentPostedIn' => array ( '7fa135d0e3284065b0e8fc6efe8791ea' => array ( 12 => 12, 13 => 13, 16 => 16, ), '052798cd3cdb2b38d443595369b750b2' => array ( 12 => 12, 13 => 13, 16 => 16, ), ), '_followData' => NULL, 'queued' => NULL, '_data' => array ( 'id' => 199, 'database_id' => 36, 'name' => 'Ready, Willing & Able,Pretaj, Volemaj, Kapablaj', 'parent_id' => 0, 'last_record_id' => 12, 'last_record_date' => 1501958376, 'last_record_member' => 2, 'last_record_name' => NULL, 'last_record_seo_name' => NULL, 'position' => 4, 'records' => 3, 'records_queued' => 0, 'record_comments' => 0, 'record_comments_queued' => 0, 'has_perms' => 1, 'show_records' => 1, 'furl_name' => 'ready-willing-able', 'meta_keywords' => '', 'meta_description' => '', 'forum_override' => 0, 'forum_record' => 0, 'forum_comments' => 0, 'forum_delete' => 0, 'forum_forum' => 0, 'forum_prefix' => '', 'forum_suffix' => '', 'page_title' => '', 'full_path' => 'ready-willing-able', 'last_title' => 'Tim Testing', 'last_seo_title' => 'tim-testing', 'allow_rating' => 0, 'fields' => '{"1":"135","2":"143","3":"144","4":"168"}', 'records_future' => 0, 'record_reviews' => 0, 'record_reviews_queued' => 0, 'options' => 0, 'template_listing' => 'listing', 'template_display' => 'display', 'override_sort' => '0', 'override_lang' => 1, 'can_view_others' => 1, 'create_permissions' => NULL, ), '_new' => false, 'changed' => array ( ), 'skipCloneDuplication' => false, )); ?> What is it I need to do to get a result which will explain to me that the variable $category has properties including _title and _description? (Sorry, I'm throwing around words like 'property' maybe incorrectly. I hope my explanation of what I'm looking for is otherwise clear.)
newbie LAC Posted May 30, 2018 Posted May 30, 2018 It's a magic You can use something like {{$class = new \ReflectionClass($category); $methods = array_map(function($method) { return $method->name; }, array_filter($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED), function($method) { return mb_substr($method->name, 0, mb_strlen('get_')) == 'get_'; })); var_dump(array_combine(array_map(function($method) { return mb_substr($method, mb_strlen('get_')); }, $methods), array_map(function($method) use($category) { $key = mb_substr($method, mb_strlen('get_')); return $category->$key; }, $methods)));}}
Meddysong Posted May 30, 2018 Author Posted May 30, 2018 1 hour ago, newbie LAC said: It's a magic Thank you for sharing the trick, magician ? I've just tried it (using $category) and the result is: array(8) { ["fields"]=> array(4) { [1]=> string(3) "135" [2]=> string(3) "143" [3]=> string(3) "144" [4]=> string(3) "168" } ["_template_listing"]=> string(7) "listing" ["_template_display"]=> string(7) "display" ["_stripTagsTitle"]=> string(32) "d22da11e733659cde0a519b537ff03c5" ["_formattedTitle"]=> string(32) "d22da11e733659cde0a519b537ff03c5" ["_sortBy"]=> NULL ["_sortOrder"]=> string(4) "DESC" ["_filter"]=> NULL } I can make sense of most of it, seeing the four field IDs used in this category, the template names etc. No sign of things like _title, _description though. Is there somewhere in the main files where this would be set out? (I tried searching _title earlier but as you might imagine there were about a billion hits.) If I see an example of how this is set out, I'll have a better idea of where to look/what search term to use next time.
newbie LAC Posted May 30, 2018 Posted May 30, 2018 46 minutes ago, Meddysong said: I can make sense of most of it, seeing the four field IDs used in this category, the template names etc. No sign of things like _title, _description though. I updated the post
Meddysong Posted May 30, 2018 Author Posted May 30, 2018 That worked perfectly - thank you! (If you'd given me ten years I still wouldn't have had time to work that out for myself ? )
Daniel F Posted May 30, 2018 Posted May 30, 2018 5 hours ago, newbie LAC said: It's a magic You can use something like {{$class = new \ReflectionClass($category); $methods = array_map(function($method) { return $method->name; }, array_filter($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED), create_function( '$v', 'return mb_substr($v->name, 0, mb_strlen(\'get_\')) == \'get_\';' ) )); var_dump(array_combine(array_map(function($method) { return mb_substr($method, mb_strlen('get_')); }, $methods), array_map(function($method) use($category) { $key = mb_substr($method, mb_strlen('get_')); return $category->$key; }, $methods)));}} Nice snippet, just a minor suggestion: create_function is deprecated since PHP 7.2, which more and more people are using, so it's time to forget it and use closures instead
newbie LAC Posted May 31, 2018 Posted May 31, 2018 13 hours ago, Daniel F said: Nice snippet, just a minor suggestion: create_function is deprecated since PHP 7.2, which more and more people are using, so it's time to forget it and use closures instead Updated!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.