我想显示检查变量是否为空,所以我制作了这段代码
{{ form_widget(form.showPrice, {% if travel is null %} {'attr': {'checked': 'checked'}} {% endif %} ) }}
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误
A hash key must be a quoted string, a number, a name, or an expression enclosed in
parentheses (unexpected token "operator" of value "%" in AppBundle:Dashboard/Travel:form.html.twig at line 100
Run Code Online (Sandbox Code Playgroud) 我正在使用liipimaginebundle,除了在更新原始图像时删除和更新缓存图像,一切正常.我想知道我该怎么做
config.yml
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
travel_75_55:
quality: 80
filters:
thumbnail: { size: [75, 55], mode: outbound }
travel_270_161:
quality: 75
filters:
thumbnail: { size: [270, 161], mode: outbound}
Run Code Online (Sandbox Code Playgroud)
这就是实体:形象
/**
* Image
*
* @ORM\HasLifecycleCallbacks
*/
class Image
{
//.................
public $file;
public function setFile($file)
{
$this->file = $file;
if (null !== $this->url) {
$this->tempFilename = $this->url;
$this->url = null;
$this->alt = null;
}
}
public function getFile()
{
return $this->file;
}
private $tempFilename; …Run Code Online (Sandbox Code Playgroud) 我是角度4的新手,我正在尝试构建我的第一个应用程序.
标题显示在屏幕上,但在控制台中出现此错误 :
这是html文件中的第26行:
<h1>{{result.title}}</h1>
Run Code Online (Sandbox Code Playgroud)
这是TravelDetailComponent:
export class TravelDetailComponent implements OnInit {
result: string[];
id: number;
constructor(private http: Http, private globals: Globals, private activatedRoute: ActivatedRoute) {
}
ngOnInit() {
this.activatedRoute.params.subscribe((params: Params) => {
this.id = params['id'];
console.log(this.id);
});
this.http.get(this.globals.baseUrl + 'travels/' + this.id)
.map(res => res.json()).subscribe(result => this.result =
result);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么标题显示在屏幕上,但我在控制台中出现此错误,我该如何解决?
我正在使用 symfony 4 和 Api Platform 2.5 。我创建了一个自定义操作来更改用户密码。
问题是当我发送一个空的 oldPassword或任何其他必需的属性时,验证不起作用。如您所见,我使用了一个名为"change_password"的验证组。
这是实体用户的一部分:
/**
* @ApiResource(
* itemOperations={
* "user_change_password"={
* "method"="PUT",
* "path"="/users/change-password/{id}",
* "controller"=UserChangePassword::class,
* "formats"={"json"},
* "denormalization_context"={"groups"={"user:change-password"}},
* "normalization_context"={"groups"={"user:read"}},
* "validation_groups"={"change_password"},
* "access_control"="is_granted('EDIT', object)",
* "access_control_message"="access denied"
* },
* },
* )
*
*/
class User implements UserInterface, \Serializable, EquatableInterface
{
/**
* @Assert\NotBlank(
* message=Tthis value should not be blank",
* groups={"change_password"}
* )
* @SecurityAssert\UserPassword(
* message = "Wrong value for your …Run Code Online (Sandbox Code Playgroud) 我刚刚安装了 liipimaginebundle 但它不起作用并且不创建文件夹和图像
应用程序/配置/路由.yml:
_liip_imagine:
resource: "@LiipImagineBundle/Resources/config/routing.xml"
Run Code Online (Sandbox Code Playgroud)
应用程序/配置/config.yml:
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
travelThumb:
quality: 80
filters:
thumbnail: { size: [120, 90], mode: inset }
Run Code Online (Sandbox Code Playgroud)
枝条:
<img src="{{ travel.image.webPath | imagine_filter('travelThumb') }}" alt="{{ travel.image.alt }}" />
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中检查元素时,我得到以下代码:
<img src="http://localhost/agence/web/app_dev.php/media/cache/resolve/travelThumb/uploads/img/travels/1.jpeg" alt="entry_big_1.jpg">
Run Code Online (Sandbox Code Playgroud)
当我在新选项卡中打开该链接检查元素时,出现此错误:
PHP exif extension is required to use the ExifMetadataReader
Run Code Online (Sandbox Code Playgroud) 我想在动作控制器之后重定向到上一页,但是我收到了这个错误. Symfony版本2.5.8
Cannot redirect to an empty URL.
500 Internal Server Error - InvalidArgumentException
Run Code Online (Sandbox Code Playgroud)
这是actiuon:
public function addFavoriteAction(Travel $travel, Request $request)
{
if (!$this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return $this->redirect($this->generateUrl('fos_user_security_login'));
}
if ($request->getMethod() == 'GET') {
$favorite = new Favorite();
$em = $this->getDoctrine()->getManager();
$favorite->setUser($this->get('security.context')->getToken()->getUser());
$favorite->setTravel($travel);
$em->persist($favorite);
$em->flush();
}
$referer = $this->getRequest()->headers->get('referer');
return $this->redirect($referer);
}
Run Code Online (Sandbox Code Playgroud)
更新
出现错误是因为我直接在浏览器地址栏中键入了操作链接.
这是输入用户名的源代码是:
<input type="text" id="user_username" name="user[username]" >
Run Code Online (Sandbox Code Playgroud)
当我尝试在控制器中获取它时,我收到此错误:
Child "username" does not exist
Run Code Online (Sandbox Code Playgroud)
控制者:
//.......
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
$i = 0;
$username = $form["username"]->getData();
$user= $em->getRepository('UsersBundle:User')->findOneByUsername($username);
//.......
}
Run Code Online (Sandbox Code Playgroud)
这是formType
class EleveType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('user', new UserType())
->add('ecole')
->add('niveauscolaire')
;
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以通过属性条件获取数组的长度,而无需在控制器中创建另一个查询。
public function pageAction()
{
$em = $this->getDoctrine()->getManager();
$pages = $em->getRepository('AppBundle:Page')->findAll();
return $this->render(':Frontend/includes:menu.html.twig', array(
'pages' => $pages
));
}
Run Code Online (Sandbox Code Playgroud)
在视图中
//number of all pages
{{ pages|length }} // output 15 (ok)
Run Code Online (Sandbox Code Playgroud)
现在是否可以从控制器返回的相同结果中获取page.activate == true的页面数?
// number of page where page.activate == true
??
Run Code Online (Sandbox Code Playgroud) 我正在使用Ionic 3,我有一些要求用户进行身份验证的功能,因此当用户点击按钮时,会显示警报.由于这些功能遍布整个项目,所以我创建了一个全局函数,显示了这个警告,但当我把它放入push()或setRoot()时,项目停止工作并出现一个空白页面.
import { Injectable, ViewChild } from '@angular/core';
//..............
@Injectable()
export class Alerts {
@ViewChild(Nav) nav: Nav;
constructor(private alertCtrl: AlertController) {
}
mustLogin() {
let alert = this.alertCtrl.create({
title: 'must login',
message: 'go to login ?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Login',
handler: () => {
this.nav.setRoot(LoginPage);
//this.nav.push(LoginPage); blank page also
}
}
]
});
alert.present();
}
Run Code Online (Sandbox Code Playgroud)
}
我正在使用 symfony 6.3 并且已经安装了ymfony/ux-swup:
//bundles.php
<?php
return [
// ..............
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Symfony\UX\Swup\SwupBundle::class => ['all' => true],
Symfony\UX\Dropzone\DropzoneBundle::class => ['all' => true],
];
Run Code Online (Sandbox Code Playgroud)
我已关注文档https://symfony.com/bundles/ux-swup/current/index.html#usage
树枝页面
<div {{ stimulus_controller('symfony/ux-swup/swup') }} id="swup" data-turbo="false">
<section class="content">
<div class="container-fluid">
my content
</div>
</section>
</div>
Run Code Online (Sandbox Code Playgroud)
但我发现这个树枝函数错误:
未知的“stimulus_controller”功能。