是否有正确的方法来自定义表单,具体取决于请求它的用户的角色?
我的场景非常简单:如果用户没有被ROLE_ADMIN授予,我需要隐藏一些字段.我试图避免在Twig上显示字段,但是
{% if is_granted('ROLE_ADMIN') %}
{{form_row(form.field)}}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
不起作用,因为表单生成器绕过此检查.
Symfony版本:2.8.2
编辑
感谢@Rooneyl 建议,我找到了解决方案:
首先,您需要将"角色"键添加到options参数.因此,在configureOptions()$options['role']中始终是ROLE_USER.
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MyBundle\Entity\Ticket',
'role' => 'ROLE_USER'
));
}
Run Code Online (Sandbox Code Playgroud)
然后在控制器中你必须传递getRoles()数组:
$user_roles = $this->getUser()->getRoles();
$form = $this->createForm('MyBundle\Form\TicketType', $ticket, array('role' => $user_roles));
Run Code Online (Sandbox Code Playgroud) 随着SolidWorks 2016的启动,DassaultSystèmes推广了一个新的Web门户,该门户可将Edrawings模型嵌入到网页中:3dcontentcentral.com。他们的Web 3D查看器使用WebGL在浏览器窗口中显示模型(您可以在此处找到一个实时示例)。此外,还可以将iframe与查看器一起嵌入,以将其嵌入到另一个网页中,如下所示:
<iframe scrolling='no' frameborder='0' allowfullscreen='true'
src='http://www.3dcontentcentral.com/external-site-embed.aspx?format=3D&catalogid=364&modelid=1254&width=250&height=250&edraw=true'
name='PreviewFrame3D' id='PreviewFrame3D' width='400' height='355'>
</iframe>
<br/>
<a href='http://www.3dcontentcentral.com/download-model.aspx?catalogid=364&id=1217'>
Download</a>
Run Code Online (Sandbox Code Playgroud)
在最后的结果是一样的东西如下:
因此,有没有机会以相同的方式导出3D模型(零件)并嵌入为WebGL,而无需上传到3D Content Central网站?如果有任何帮助,我也可以访问Edrawings / SolidWorks SDK(2015)。
是否可以在 AWS ElastiCache 或 MemoryDB 中安装 RediSearch(Redis 模块)?手动创建倒排索引可能会非常痛苦,如果 AWS 中提供此功能就好了。我找到了使用 EC2 安装它的可能解决方法,但对于面向生产的使用,此解决方案不可行。如果有一个可使用 RediSearch 的托管解决方案会好得多。
我发现也可以将RediSearch作为来自 AWS、Azure 和 GCP 上的 Redis Labs 的Redis Enterprise Cloud上的服务,但我想知道是否可以直接在 AWS 中提供此模块,而无需支付额外的许可证。例如,RedisJson 应该已经在 AWS 中可用。
关于这个老问题, AWS 支持人员确认,到 2021 年,不可能在 AWS ElastiCache 中使用开箱即用的RediSearch 。2023年还是这样吗?
amazon-web-services redis amazon-elasticache redisearch amazon-memory-db
我想使用一个简单的 TypeScript 函数来访问NetworkInformation接口,如下所示:
private checkNetworkConnection(): void {
const connection = Navigator.connection
|| navigator.mozConnection
|| navigator.webkitConnection;
const type = connection.type;
console.log('CONNECTION TYPE: %o', type);
console.log('DOWNLINK: %o', connection.downlink);
}
Run Code Online (Sandbox Code Playgroud)
事实是我不断地返回错误connection is undefined。环顾四周,我发现使用 Cordova 的人扩展了 Typescript 导入的类型定义@types/cordova-plugin-network-information,但这并不能解决我的问题。
可以在此处找到一个有效的 StackBlitz 示例。
我想使用Three.js(@types/three/index)扩展导入到ng6项目中的类型定义,并使用一组将直接附加到相同“名称空间”的函数。类似于:THREE.myFunction()。我不想声明三any来抑制类型检查和linter,并且我想可以包装一个使用JS类/功能扩展三个的香草JS函数,然后再利用typings.d.ts。
首先,我想将THREE.js加载程序导入到我的项目中,这通常定义了一个可扩展的vanilla函数THREE。
我正在尝试将BinaryLoaderng服务导入ng服务,但不确定如何以正确的方式进行操作。
到目前为止,我所做的是:
npm install three --savenpm install @types/three --save-devimport * as THREE from 'three';scripts数组中angular.json
"scripts": [
"./node_modules/three/examples/js/loaders/BinaryLoader.js"
]
Run Code Online (Sandbox Code Playgroud)
到目前为止一切顺利,但是现在我需要创建一个二进制加载器:
import * as THREE from 'three';
// import { BinaryLoader } from 'three';
// import 'three/examples/js/loaders/BinaryLoader';
export class ThreeManagerService {
const loader = new THREE.BinaryLoader();
...
Run Code Online (Sandbox Code Playgroud)
而且我必须找到BinaryLoader以@types/three/index某种方式添加的方法。这样,我应该能够扩展类型定义,以便能够创建新类型THREE.BinaryLoader。可以做这样的事情吗?
我得到的警告是:
警告:./src/app/shared/three-manager.service.ts 24:25-43“在'三个'中找不到导出'BinaryLoader'(导入为'三个') …
我需要绑定这个特征的实现:
trait ClientRepository[F[_]] {
def list(): F[Iterable[ClientDTO]]
}
Run Code Online (Sandbox Code Playgroud)
对于这个实现:
import cats.effect.IO
@Singleton
class ClientRepositoryImpl @Inject()(db: OldDataBase, c: IOContextShift)
extends ClientRepository[IO] {
override def list(): IO[Iterable[ClientDTO]] = ???
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 Scala Play!v2.7.2 和 Scala v2.12.8,以及scala-guicev4.2.1。为了将特征绑定到它的实现,我想在我的中做类似的事情Module.scala:
class Module(environment: Environment, configuration: Configuration)
extends AbstractModule
with ScalaModule {
override def configure() = {
bind[ClientRepository].to[ClientRepositoryImpl[IO]].in[Singleton]
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
[error] app/Module.scala:37:9: kinds of the type arguments (ClientRepository) do not conform to the expected kinds of the type parameters (type T).
[error] ClientRepository's …Run Code Online (Sandbox Code Playgroud) angular ×2
3d ×1
angular-cli ×1
angular6 ×1
formbuilder ×1
guice ×1
html5 ×1
redis ×1
redisearch ×1
scala ×1
solidworks ×1
symfony ×1
symfony-2.8 ×1
three.js ×1
typescript ×1