Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我可以将dictionary对象传递给Restler吗?_Php_Restler - Fatal编程技术网

Php 我可以将dictionary对象传递给Restler吗?

Php 我可以将dictionary对象传递给Restler吗?,php,restler,Php,Restler,我知道我可以指定“array”作为数组的类型,但是当我想将字典类型传递给使用Restler 3的方法时,我应该使用什么呢 传递给POST方法的整个“外部”块当然是字典类型,但现在我希望其中一个参数也是字典类型。请求中的字典 将字典定义为具有公共属性的类 class Object { public $property = 'value'; /** * @var string {@required false} */ public $optional

我知道我可以指定“array”作为数组的类型,但是当我想将字典类型传递给使用Restler 3的方法时,我应该使用什么呢

传递给POST方法的整个“外部”块当然是字典类型,但现在我希望其中一个参数也是字典类型。

请求中的字典 将字典定义为具有公共属性的类

class Object
{
    public $property = 'value';

    /** 
     * @var string {@required false} 
     */
    public $optional = 'value';

    //add more properties here
}
让您的api方法将其用作其参数之一

class Api
{
    public function method(Object $obj, $name)
    {
        //use $obj->property here
    }
}

回应词典 为此,可以使用关联数组(带字符串索引的数组)或
stdClass
的实例

return array {

    'name' => 'Gargoyle'
    'object' => array {
        'property' => 'value'
    }

};


两者都会产生一个JSON对象输出

我知道如何在PHP中创建assoc数组,但我正试图找出如何使其与restler REST api一起工作。我不确定我是否得到了您想要的!您是否试图将字典作为API方法的属性之一传递,并想知道如何接收它?正确。我不知道在方法注释的@param后面应该放什么。我已经为你更新了答案!如果你需要一个实际的例子,请看我注意到,如果我像你一样在一行上做@var注释,我会得到“第559行的…/Routes.php中不支持的操作数类型”。将其设置为多行格式不会引发异常。
$r = new stdClass();
$r->name = 'Gargoyle';
$r->object = new stdClass();
$r->object->property = 'value';
return $r;