1

我正在尝试回显当前用户的 character_name。如何获得这一点是使用 default_character_id 并遍历字符列表并获取该字符的名称。然后在其下方显示一个下拉菜单,其中包含 characters 属性内的其他字符。

关于如何实现这一点的任何想法?

object(stdClass)#26 (18) {
  ["user_id"]=>
  string(5) "10004"
  ["role_id"]=>
  string(1) "4"
  ["default_character_id"]=>
  string(1) "1"
  ["characters"]=>
  array(3) {
    [0]=>
    object(stdClass)#30 (6) {
      ["id"]=>
      string(1) "3"
      ["character_name"]=>
      string(5) "twilliams"
      ["user_id"]=>
      string(5) "10004"
    }
    [1]=>
    object(stdClass)#31 (6) {
      ["id"]=>
      string(1) "4"
      ["character_name"]=>
      string(4) "ksmith"
      ["user_id"]=>
      string(1) "0"
    }
    [2]=>
    object(stdClass)#32 (6) {
      ["id"]=>
      string(1) "5"
      ["character_name"]=>
      string(11) "tjones"
      ["user_id"]=>
      string(1) "0"
    }
  }
}

<a href="" data-toggle="dropdown" class="glyphicons cogwheel">
    <i></i>
    <?php
    //echo character name of logged in user
    ?>
    <span class="caret"></span>
 </a>
<ul class="dropdown-menu pull-right">
    <li><a href="">Some option</a></li>
    <li><a href="">Some other option</a></li>
    <li><a href="">Other option</a></li>
</ul>
4

1 回答 1

2
<a href="" data-toggle="dropdown" class="glyphicons cogwheel">
    <i></i>
    <?php
      echo $object->characters[$object->default_character_id]->charachter_name;
    ?>
    <span class="caret"></span>
 </a>
<ul class="dropdown-menu pull-right">
    <li><a href="">Some option</a></li>
    <li><a href="">Some other option</a></li>
    <li><a href="">Other option</a></li>
</ul>
于 2013-08-16T19:24:35.583 回答