小编Vik*_*293的帖子

如何在Yii2 restful controller中执行其他任务?

这是我的RESTful控制器的样子.

<?php

namespace backend\controllers;
use yii\rest\Controller;
use yii;
use yii\web\Response;
use yii\helpers\ArrayHelper;


class UserController extends \yii\rest\ActiveController
{
  public function behaviors()
  {
    return ArrayHelper::merge(parent::behaviors(), [
      [
        'class' => 'yii\filters\ContentNegotiator',
        'only' => ['view', 'index'],  // in a controller
        // if in a module, use the following IDs for user actions
        // 'only' => ['user/view', 'user/index']
        'formats' => [
          'application/json' => Response::FORMAT_JSON,
        ],
        'languages' => [
          'en',
          'de',
        ],
      ],
      [
        'class' => \yii\filters\Cors::className(),
        'cors' => [
          'Origin' => ['*'],
          'Access-Control-Request-Method' => ['GET', …
Run Code Online (Sandbox Code Playgroud)

php api rest yii-components yii2

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

为什么 immer.js 不允许在草稿上设置动态属性?

//I want my action to dispatch payload like
// {type:'update',payload:{'current.contact.mobile':'XXXXXXXXX'}}
//In reducer dynamically select the segment of state update needs to be applied to 
//Below code doesn't work as expected though, draft always remains at same level
draft = dA.key.split('.').reduce((draft, k) => {
  return draft[k]
}, draft);

//Or an ideal syntax may look like below line
draft['current.contact.mobile'] = dA.value;


//Code that works
draft['current']['contact']['mobile'] = dA.value;
Run Code Online (Sandbox Code Playgroud)
我希望我的操作可以分派有效负载,例如 {type:'update',payload:{'current.contact.mobile':'XXXXXXXXX'}} 并且在 reducer 中动态选择需要更新的状态段。这样做有什么根本性的错误吗,我相信这可以让生活更轻松。有什么可以做到的吗?

javascript immutability reactjs react-redux immer.js

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