在我的 Web 应用程序中,当我定义必须包含某种数据类型的类属性时,我总是指定此数据类型。但应用程序异步获取数据,因此实际上该属性具有未定义的值,然后它具有真实的数据:
class SomeClass {
a: ISomeData;
constructor() {
getDataAsync().then((res: ISomeData) => this.a = res);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这a: ISomeData是不正确的。一定是a: ISomeData | undefined。(如果this.a = someData在构造函数中同步设置,那就是正确的)是否有 tslint 规则用于检查类属性没有数据并且必须具有未定义的类型?
我使用doctrine2和ZF2,我的一些库使用Zend\Db\Adapter\Adapter,其他库使用doctrine2.现在,他们连接到数据库两次.是否可以在doctrine和标准ZF2 db适配器中使用一个db连接?
我使用AWS API Gateway将HTTP查询代理到我的服务.我的服务如何检查HTTP请求是否来自AWS API Gateway?
我正在我的 Web 应用程序中进行实时更新。该应用程序使用aws-iot-device-sdk连接到 AWS IOT :
const client = awsIot.device({
region: awsConfig.region,
protocol: 'wss',
accessKeyId: <accessKey>,
secretKey: <secretKey>,
sessionToken: <sessionToken>,
port: 443,
host: <iotEndpoint>
});
client.on('connect', res => {
// ok
});
Run Code Online (Sandbox Code Playgroud)
然后我向我的 API 发送请求,以在包含 IOT 主题 ID 的数据库表中创建记录。然后应用程序订阅此主题 ID:
client.subscribe(topicId)
Run Code Online (Sandbox Code Playgroud)
当客户端与 IOT 断开连接时,我想删除数据库中的记录。我该怎么做?我看到IOT中存在断开连接事件。但我不明白如何在 AWS lambda 中处理这个事件。
我想查找带有最新"sorting_index"字段的文档.我试试这样:
var sorting_index = -1;
this.findOne().sort({'sorting_index': -1}).exec(function(err, doc) {
if (err) return;
sorting_index = doc['sorting_index']; // sorting_index == 10
});
console.log(sorting_index); // sorting_index == -1
Run Code Online (Sandbox Code Playgroud)
问题是回调是异步的.如何同步?
我有一个用户模型,它与角色模型具有“多对多”关系。用户模型:
class User extends Model
{
...
public function roles()
{
return $this->belongsToMany(Config::get('entrust.role'), Config::get('entrust.role_user_table'), 'user_id', 'role_id');
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个用户控制器,它有一种以 JSON 格式获取用户数据的方法:
class UserController extends Controller {
...
// GET /user/3
public function show(User $user)
{
// $user is a single user
// return single user's data without roles
// I want to get user WITH roles
return $user;
}
// GET /users
public function index(User $user)
{
// returns list of users with roles.
$user->with('roles')->get();
}
}
Run Code Online (Sandbox Code Playgroud)
该方法show()以 …
我在我的 Web 应用程序中使用 AWS Cognito 身份验证。我有一个带有 REST API 的 PHP 后端。用户身份验证后,我使用此库向 AWS API Gateway 发出请求。API 网关方法具有 HTTP 集成类型。他们将 HTTP 请求代理到我的 PHP 后端。如何在我的 PHP 后端获取 Cognito Identity Id?我需要在后端设置对 Cognito 用户的关系引用。
aws-cognito ×1
aws-iot ×1
css ×1
doctrine-orm ×1
eloquent ×1
html ×1
laravel ×1
laravel-5.2 ×1
mongodb ×1
mongoose ×1
svg ×1
tslint ×1
typescript ×1