小编Ami*_*rma的帖子

php获取唯一的子数组

我想在PHP中获得一个解决方案,以获得基于子阵列基础的独特阵列.像这样

Array
(
[0] => Array
    (
        [0] => 1227
        [1] => 146
        [2] => 1
        [3] => 39
    )

[1] => Array
    (
        [0] => 1227
        [1] => 146
        [2] => 1
        [3] => 39
    )

[2] => Array
    (
        [0] => 1228
        [1] => 146
        [2] => 1
        [3] => 39
    )
)
Run Code Online (Sandbox Code Playgroud)

Array
(
[0] => Array
    (
        [0] => 1227
        [1] => 146
        [2] => 1
        [3] => 39
    )

[1] => Array
    (
        [0] …
Run Code Online (Sandbox Code Playgroud)

php arrays

5
推荐指数
1
解决办法
1506
查看次数

cakephp加载组件飞

我想在cakePHP中加载组件在此示例中,为json响应动态加载RequestHandler组件

public function xyz() {

    $this->components[] ='RequestHandler';
    $this->Components->load('RequestHandler');
    $this->RequestHandler->initialize($this);

    $abc = array("hello","world");
    $this->set('abc', $abc);
    $this->set('_serialize', array( 'abc'));
}
Run Code Online (Sandbox Code Playgroud)

初始化函数生成的错误显示未定义.

修订更清晰的图片:

public function xyz() {
    $this->components[] ='RequestHandler';
    $this->RequestHandler =  $this->Components->load('RequestHandler');
    $this->RequestHandler->initialize($this);

    $abc = array("hello","world");
    $this->set('abc', $abc);
    $this->set('_serialize', array( 'abc'));
}
Run Code Online (Sandbox Code Playgroud)

我也试过了

public function xyz() {

    $this->RequestHandler =  $this->Components->load('RequestHandler');
    $abc = array("hello","world");
    $this->set('abc', $abc);
    $this->set('_serialize', array( 'abc'));
}
Run Code Online (Sandbox Code Playgroud)

我不能使用这样的组件#$ this-> RequestHandler-> getTime(); 因为cakephp自动处理json respone.当我使用http://disecake.localhost/resources/xyz.json点击上面的代码时

{"code":500,"url":"/ resources/xyz.json","name":"查看文件"/var/www/disecake/app/View/Resources/xyz.ctp"缺失."}

我用的时候

public $components = array( 'RequestHandler'); 
在我的cotroller比输出

{"abc":["hello","world"]}

我想现在问题更清楚了.

php cakephp

1
推荐指数
1
解决办法
9577
查看次数

标签 统计

php ×2

arrays ×1

cakephp ×1