我在生产中有一个Symfony项目,运行后sudo php app/console cache:clear --env=prod,文件夹的权限变为
drwxr-xr-x 11 root root 4096 Feb 29 15:08 prod
这不允许用户www-data(apache默认用户)再访问它.
如何清除缓存并将www-data读/写到缓存文件夹?
此外,运行php console cache:cleardev模式我得到了
dev.log文件并创建了以下权限:
The stream or file "../app/logs/dev.log" could not
be opened: failed to open stream: Permission denied-rw-r--r-- 1 www-data www-data 2840530 Feb 29 15:01 dev.log
我正在使用SonataMediaBundle来跟踪我的图像.我可以使用Sonata的助手在树枝上渲染图像:
{% media user.profilepic, 'reference' %}
Run Code Online (Sandbox Code Playgroud)
这将呈现为 <img src="the src">
但是,我想要获得的是裸路径,所以我可以为我的img添加一个类.就像是:
<img class="img-responsive" src="{{ asset(user.profilepic) }}">
Run Code Online (Sandbox Code Playgroud)
显然, asset(user.profilepic)不返回路径,而是返回对象,并且该对象似乎不包含图像的路径.
编辑
找到了我的答案的一部分:
{% set foo %}
{% path image, 'small' %}
{% endset %}
<img src="{{ asset(foo) }}" alt=""/>
Run Code Online (Sandbox Code Playgroud)
显然,块的输出可以设置为变量,然后将其传递给资产函数.
如果我有一个安全的路由,让我们说panel如下,Symfony将只允许登录用户访问.
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/panel, role: ROLE_USER }
Run Code Online (Sandbox Code Playgroud)
对于未登录的用户,它总是将它们重定向到login_path(我使用的是FOSUserBundle):
security:
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: fos_user_security_login
Run Code Online (Sandbox Code Playgroud)
我在哪里可以禁用或覆盖此重定向?我想直接显示登录表单,而不重定向用户.
我认为它与此有关AccessDeniedHandlerInterface,但是在security.yml中需要覆盖哪些密钥?默认实现在哪里?
对于我们拥有的其他情况DefaultLogoutSuccessHandler, DefaultAuthenticationFailureHandler, DefaultAuthenticationSuccessHandler,我们可以针对这些情况中的每一种实现服务,这扩展了它们各自的接口并且可以以自定义方式处理该情况.但是,找不到AccessDenied的任何内容.其目录仅包含接口.
我有一个特殊的问题,但我会让这个例子更普遍。我有一个带有强制构造函数参数和一些可选参数的父类,每个参数都有一个默认值。然后,我从它继承Child并添加一个强制参数,并从Child继承GrandChild并向构造函数添加另一个强制参数。结果与此类似:
class Parent():
def __init__(self, arg1, opt_arg1='opt_arg1_default_val', opt_arg2='opt_arg2_default_val',
opt_arg3='opt_arg3_default_val', opt_arg4='opt_arg4_default_val'):
self.arg1 = arg1
self.opt_arg1 = opt_arg1
self.opt_arg2 = opt_arg2
self.opt_arg3 = opt_arg3
self.opt_arg4 = opt_arg4
class Child(Parent):
def __init__(self, arg1, arg2, opt_arg1, opt_arg2, opt_arg3, opt_arg4):
super().__init__(arg1, opt_arg1, opt_arg2, opt_arg3, opt_arg4)
self.arg2 = arg2
class GrandChild(Child):
def __init__(self, arg1, arg2, arg3, opt_arg1, opt_arg2, opt_arg3, opt_arg4):
super().__init__(arg1, arg2, opt_arg1, opt_arg2, opt_arg3, opt_arg4)
self.arg3 = arg3
Run Code Online (Sandbox Code Playgroud)
问题是这看起来相当难看,特别是如果我想从 Child 继承更多的类,我必须复制/粘贴该新类的构造函数中的所有参数。
在寻找解决方案时,我发现可以使用 **kwargs 解决这个问题,如下所示:
class Parent(): …Run Code Online (Sandbox Code Playgroud) <input type="text"></input>
Run Code Online (Sandbox Code Playgroud)
焦点对准时,该字段默认显示蓝色边框。在哪里可以找到它的默认值和颜色代码?我想添加我自己的,但它被覆盖了。我想删除它,但随后想将其添加回来,并且在不知道默认值的情况下无法添加。
我在另一个linearlayout中有一个linearlayout和一个textview.显示内部的linearlayout,但问题是最后的textview不是.为什么?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Scrie un cuvant" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<EditText
android:id="@+id/cuvant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/cuvant_hint"
android:inputType="text" />
<Button
android:id="@+id/cuvantbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cuvantbutton_text" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Sau random" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
看看这里,

我在 security.yml 中为我的网站定义安全性
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/ad/new, role: ROLE_USER }
- { path: ^/myAds, role: ROLE_USER }
- { path: ^/payments, role: ROLE_USER }
- { path: ^/pay, role: ROLE_USER }
Run Code Online (Sandbox Code Playgroud)
但我不确定如何在此处添加这样的路线:
mybundle_contact_advertiser:
path: /ad/{id}/contact
defaults: { _controller: MyBundle:Default:contactAdvertiser,id:null}
Run Code Online (Sandbox Code Playgroud)
id考虑到我不能这样做,如何定义:
- { path: ^/ad, role: ROLE_USER }
Run Code Online (Sandbox Code Playgroud)
作为一条路线
mybundle_ad:
path: /ad/{id}
defaults: { _controller: MyBundle:Default:viewAd ,id:null}
Run Code Online (Sandbox Code Playgroud)
不适用于未注册的用户。
我想创建一个字符串“test/”,但我无法在初始字符串后添加斜杠。知道为什么以及如何吗?
string imgpath="test";
strcat(imgpath,"/");
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止尝试过的。我得到
Error 1 error C2664: 'strcat' : cannot convert parameter 1 from 'std::string' to 'char *'
Run Code Online (Sandbox Code Playgroud)
而另一个
imgpath="test"+"/";
Error 1 error C2110: '+' : cannot add two pointers
Run Code Online (Sandbox Code Playgroud)