【问题标题】:Using the REST API with PHP - Redmine将 REST API 与 PHP 一起使用 - Redmine
【发布时间】:2014-12-02 14:53:32
【问题描述】:

我使用的 API 在这里:

http://www.redmine.org/projects/redmine/wiki/Rest_api_with_php

代码:(如果链接不可用)

<?php
require_once ('ActiveResource.php');

class Issue extends ActiveResource {
    var $site = 'http://username:password@192.168.199.129:3000/';
    var $request_format = 'xml'; // REQUIRED!
}

// create a new issue
$issue = new Issue (array ('subject' => 'XML REST API', 'project_id' => '1'));
$issue->save ();
echo $issue->id;

// find issues
$issues = $issue->find ('all');
for ($i=0; $i < count($issues); $i++) {
    echo $issues[$i]->subject;
}

// find and update an issue
$issue->find (1);
echo $issue->subject;
$issue->set ('subject', 'This is the new subject')->save ();
// update status
$issue->set ('status_id', 2)->save();

// delete an issue
$issue->find (1);
$issue->destroy ();
?>

我正在尝试使用此 API 访问 Redmine 数据库并解决一些没有人分配给它的问题。

这是一个自定义方法的示例(如 ActiveResource.php 使用中所示)。

// custom method
$songs = $song->get ('by_year', array ('year' => 1999)); 

最后,我的代码:

require_once ('ActiveResource.php');


class Issue extends ActiveResource {
    var $site = 'root:12345@localhost/redmine';
    var $request_format = 'xml'; // REQUIRED!
    var $element_name = 'issue'
}

   $issue = new Issue();
   $issues = $issue->find('all'); //Works fine
   print_r($issues);

问题:

我只想得到assigned_to_id为空的问题,所以我尝试了

$issues = $issue->find ("all", array('assigned_to_id'=>null)); //not working
$issues = $issue->find (false, array('assigned_to_id'=>null)); //not working
$issues = $issue->get ('by_assigned_to_id', array('assigned_to_id' => null)) //not working

这些都不起作用,有什么问题或我错过了什么?

更多参考:http://www.redmine.org/projects/redmine/wiki/Rest_Issues

【问题讨论】:

    标签: php rest redmine


    【解决方案1】:

    这是一个疯狂的猜测,但我想知道你是否可以传递 *.这就是我在搜索分配给 none 时在 url 中看到的内容。

    $issues = $issue->find ("all", array('assigned_to_id'=>'*'));
    

    【讨论】:

    • 这不是解决方案,但感谢您的帮助。这里的问题是因为该字段在数据库中为空,当方法 find 运行时,xml 中的标签 没有创建。我试图在 ActiveResource.php 中更改它,但没有找到我应该在哪里更改。所以我只是调用 find('all') 并循环所有问题,如果未设置 assignment_to,那就是我想要的。不是最好的解决方案,但是好的,它可以工作......
    猜你喜欢
    • 2016-07-16
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    • 1970-01-01
    • 2017-07-22
    相关资源
    最近更新 更多