我们正在使用Symfony2构建一个新站点,而Assetic看起来非常有希望进行资源管理,特别是自动将所有js/css文件组合和处理.
我们将拥有一些在网站范围内使用的资源,以及一些特定于特定页面的资源.我们还将使用三层继承的模板方法.
有没有办法将这两个概念结合起来,即在继承的模板中自动添加其他资源,以便它们都作为单一资源输出?
我本周末开始学习Symfony 2.我没有遇到任何问题,因为我认为框架已有详细记录.
我正在使用FOSUserBundle包进行ACL.我想知道是否有可能使它类似于Yii框架:
$bizRule='return Yii::app()->user->id==$params["post"]->authID;';
$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);
$task->addChild('updatePost');
Run Code Online (Sandbox Code Playgroud)
您可能会在上面的代码段中看到所有详细信息.
如何实现与Symfony 2类似的功能?这可能吗?
我需要从控制器方法移动我的模型,所以我得到帮助将其更改为服务.服务本身可以工作,但我需要能够从这个服务内部连接到doctrine和kernel.起初我试图启用教义,但这造成了问题.我怎样才能做到这一点?我跟着文档并得到了这段代码.我不知道为什么我得到下面的错误.提前谢谢你的帮助.
我的配置是:
CSVImport.php
namespace Tools\TFIBundle\Model;
use Doctrine\ORM\EntityManager;
class CSVImport {
protected $em;
public function __construct( EntityManager $em ) {
$this->em = $em;
}
Run Code Online (Sandbox Code Playgroud)
应用程序/配置/ config.yml
services:
csvimport:
class: Tools\TFIBundle\Model\CSVImport
arguments: [ @doctrine.orm.entity_manager ]
Run Code Online (Sandbox Code Playgroud)
控制器中的动作
$cvsimport = $this->get('csvimport');
Run Code Online (Sandbox Code Playgroud)
我的错误
Catchable Fatal Error: Argument 1 passed to
Tools\TFIBundle\Model\CSVImport::__construct() must be an instance of
Doctrine\ORM\EntityManager, none given, called in
.../Tools/TFIBundle/Controller/DefaultController.php on line 58 and defined in
.../Tools/TFIBundle/Model/CSVImport.php line 12
Run Code Online (Sandbox Code Playgroud)
编辑,我的工作代码:
附加了内核的服务类代码
namespace Tools\TFIBundle\Model;
use Doctrine\ORM\EntityManager,
AppKernel;
class CSVImport {
protected $em;
protected $kernel; …Run Code Online (Sandbox Code Playgroud) 什么解决方案更好,建议用于短串元素?要定义块并让用户覆盖它的内容,例如:
<title>{% block title %}{% endblock %}</title>
Run Code Online (Sandbox Code Playgroud)
或者创建变量块,设置它们的默认值并让用户导入他想要的块重置变量:
基本模板:
{% block variables %}
{% set meta.title = '' %}
{% endblock %}
<title>{{ meta.title }}</title>
Run Code Online (Sandbox Code Playgroud)
用户模板:
{% block variables %}
{{ parent() }}
{% set meta.title = 'some title' %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud) 我有symfony2自定义验证器的定义:
// Nip.php
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Nip extends Constraint
{
public $message = 'This value %string% is not a valid NIP number';
//...
Run Code Online (Sandbox Code Playgroud)
这是验证码:
// NipValidator.php
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class NipValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
$stringValue = (string) $value;
$nip = preg_replace('/[ -]/im', '', $stringValue);
$length = strlen($nip);
if ($length != 10) {
$this->context->addViolation(
$constraint->message,
array('%string%' => $value)
);
return;
}
//...
Run Code Online (Sandbox Code Playgroud)
和我的翻译文件:
// validators.pl.yml
validator.nip: %string% to …Run Code Online (Sandbox Code Playgroud) 我尝试仅使用 iOS 14 SwiftUI 地图创建带有注释和叠加层的地图视图。我设法创建注释,但由于 MKMapView 委托缺少 MKOverlayRenderer,因此无法创建可见的叠加层。如何附加到地图视图委托以便它可以运行其方法
Map(coordinateRegion: $region, showsUserLocation: true, userTrackingMode: $userTrackingMode, annotationItems: annotations)) { annotation in
MapAnnotation(coordinate: CLLocationCoordinate2DMake(annotation.latitude, annotation.longitude),
anchorPoint: CGPoint(x: 0.5, y: 0.7)) {
NavigationLink(destination: DetailsView()) {
VStack {
Image(systemName: "mappin")
.font(.title)
.foregroundColor(.red)
Text(annotation.name.split(separator: " ").joined(separator: "\n"))
.font(.caption)
.bold()
.multilineTextAlignment(.center)
.foregroundColor(.black)
.padding(2)
.background(RoundedRectangle(cornerRadius: 4).fill(Color.white.opacity(0.8)))
.layoutPriority(1)
}
}
}
}
.addOverlays(mapOverlays, delegate: mapDelegate)
Run Code Online (Sandbox Code Playgroud)
和地图扩展方法:
extension Map {
func addOverlays(_ overlays: [MKOverlay], delegate: MKMapViewDelegate) -> some View {
// MKMapView.appearance().delegate = delegate // THIS DOES NOT WORK AT …Run Code Online (Sandbox Code Playgroud) 我知道类似的问题是在3年前被问过的(Doctrine2在By By之前排序)但也许从那时起事情发生了变化.
我有2个实体财产:
orderId
orderUpdateDate
Run Code Online (Sandbox Code Playgroud)
两者都被设置为唯一,但对于列表我需要上次更新日期,所以排序应该是
order by orderUpdateDate DESC
Run Code Online (Sandbox Code Playgroud)
然后按orderId分组,所以我只有一次订单.
group by orderId
Run Code Online (Sandbox Code Playgroud)
问题是,当我在查询构建器中的一个查询中粘贴时,我得到了订单的随机列表
我已经设置了 git post-commit 钩子,它会在我的多分支管道上触发扫描。此扫描检测更改(新提交),但不会触发更改分支的构建作业。
Scan Multibranch Pipeline Log
Branch indexing
... git messages ...
Checking branches...
Checking branch develop
‘Jenkinsfile’ found
Met criteria
No changes detected: develop (still at 5ed9c9a76ef81bf023c1ea89c7515458e8ac548d)
Checking branch master
‘Jenkinsfile’ found
Met criteria
No changes detected: master (still at c9ac551806eb5a90dccf093e58c907f330407b9b)
Checking branch feature/Model
‘Jenkinsfile’ found
Met criteria
Changes detected: feature/Model (2e5a898498e138737941a907969eb80ee533a900 ? b931de01b1f8dd51a2646f109b185592ea941f7f)
Did not schedule build for branch: feature/Model
Processed 3 branches
...
Finished: SUCCESS
Run Code Online (Sandbox Code Playgroud)
因此,现在我必须手动启动所有作业。
我发现了类似的问题:没有为分支安排构建,但没有解决如何解决这个问题的答案。
你能帮我吗?
当我将图像存储在我的包中时,dir结构显示图像很容易使用Assetic从文档中获取:
{% image '@AcmeFooBundle/Resources/public/images/example.jpg'
filter='jpegoptim' output='/images/example.jpg'
%}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}
Run Code Online (Sandbox Code Playgroud)
但是如何为我上传的图片使用资产?在我的getWebPath下面返回相对于web dir的路径,例如:"/ uploads/images/images.jpg".也许这个解决方案没问题,没有必要使用资产?我认为将它用于像jpegoptim这样的过滤可能很有用
<img src="{{app.request.basepath}}/{{ entity.getWebPath }}">
Run Code Online (Sandbox Code Playgroud) 当我在表单控制器中设置CSS类并将其作为$ options数组元素传递时,它可以工作.
private function createEditForm(OrderCard $entity)
{
$form = $this->createForm(new OrderCardType($this->get('security.context')
->isGranted('ROLE_SUPER_ADMIN')), $entity, array(
'action' => $this->generateUrl('ordercard_update', array('id' => $entity->getId())),
'attr'=>array(
'class'=>'form-horizontal'
)
));
return $form;
}
Run Code Online (Sandbox Code Playgroud)
但是当我想使用formType获得相同的效果时,它不会添加到表单中:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// not works
->setAttribute('attr', array('class' => 'form-horizontal'))
// not works either
->setAttribute('class', 'form-horizontal')
//...
Run Code Online (Sandbox Code Playgroud)
我做错了什么?如何使它工作?
如何.env在运行RunVapor 项目的方案时强制 Xcode 加载文件?
我--env production在方案配置中添加了运行参数,但它也没有改变行为。只有在 Xcode 环境变量下设置才有效(但这不是我的目标,因为当我在 Xcode 之外重建蒸汽项目时它们会被重置。
我已经定义了几个变量,但是在项目运行时它们无法加载(密钥不存在)
编辑:
更新问题以说明我使用 Vapor 3
如何将 WHERE x LIKE $xyz 添加到查询构建器?
我开始
let searchQuery = try? request.query.get(String.self, at: "s")
...
query.where(\Talk.title, SwifQL.like(searchQuery))
Run Code Online (Sandbox Code Playgroud)
但是接下来我要搜索不区分大小写的字符串我有错误:
[ ERROR ] PostgreSQLError.server.error.scanner_yyerror: GET /testroute?s=Swift syntax error at or near "$8" (ErrorMiddleware.swift:26)
symfony ×8
twig ×3
doctrine-orm ×2
vapor ×2
acl ×1
assetic ×1
assets ×1
block ×1
css ×1
delegates ×1
dql ×1
forms ×1
git ×1
image ×1
jenkins ×1
kernel ×1
mapkit ×1
model ×1
resources ×1
swift ×1
swiftui ×1
templates ×1
translation ×1
uikit ×1
validation ×1
vapor-fluent ×1
variables ×1
xcode ×1
yii ×1