目标:使用 PHP/CodeIgniter,我需要在可用数组中获取用户列表及其自定义字段名称和值。如果我能拿到物品,我可以做我需要的。请参阅带有“// <<<”注释的输出,这样您就可以看到我卡在哪里了。我只是无法超越 [@attributes]。
我正在使用 PHP 使用 ActiveResource.php 及其内置的 REST API 连接到 Redmine。我想获得所有用户的列表,并得到下面的输出。
模型/Employees_model.php:
<?php
require_once ('ActiveResource.php');
class Employees_model extends ActiveResource {
var $site = 'http://user:password@localhost:8080/redmine/';
var $element_name = 'user';
var $request_format = 'xml';
function __construct() {
parent::__construct();
}
}
?>
控制器/employees.php:
public function employees () {
$employees = new Employees_model();
$data['employeeList'] = $employees->find('all');
$this->load->view('customers/ajaxEmployees', $data);
}
查看/ajaxEmployees.php:
<?php
//I can get the following with no problem
echo $employee->id . "<br/>";
echo $employee->firstname . "<br/>";
echo $employee->lastname . "<br/>";
//This is where I'm stuck (see OUTPUT for [@attributes] and "// <<<" notes)
echo $employee->custom_fields->custom_field;
?>
输出:
Array
(
[0] => Employees_model Object
(
[id] =>
[site] => http://user:password@localhost:8080/redmine/
[element_name] => user
[request_format] => xml
[extra_params] =>
[user] =>
[password] =>
[element_name_plural] => users
[_data] => Array
(
[id] => 16
[login] => jschmoe
[firstname] => Joe
[lastname] => Schmoe
[mail] => joe@example.com
[created_on] => 2012-08-24T01:58:21Z
[last_login_on] => SimpleXMLElement Object
(
)
[custom_fields] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => array
)
[custom_field] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => Quality Control //<<< I need this
[id] => 2
)
[value] => 1 //<<< I need this to know that QualityControl = 1
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => Technical Contractor // <<< I need this
[id] => 3
)
[value] => 0 // <<< I need this to know that TechnicalContractor = 0
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => Content //<<< I need this
[id] => 4
)
[value] => 0 // <<< I need this to know Content = 1
)
)
)
)
)
)
非常感谢大家的帮助。在浪费了许多小时四处寻找,尝试了我遇到的所有事情和我能想到的所有事情之后——我想我最好挥动我的小白旗。:(