我有一个简单的登录表单:
public function loginAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render(
'users/login.html.twig',
[
'page' => 'login',
'last_username' => $lastUsername,
'error' => $error,
]
);
}
Run Code Online (Sandbox Code Playgroud)
security.yml:
secured_area:
form_login:
provider: user_db_provider
login_path: /login
check_path: /login
csrf_token_generator: security.csrf.token_manager
Run Code Online (Sandbox Code Playgroud)
我正在尝试设置用户的上次登录时间.
难道我真的要创建一个新的监听器,并写一整类,像这样的回答,只为这单指令:$user->setLastLogin(new \DateTime());?或者是否有更简单的东西,比如把它放在控制器中?
我正在学习Symfony,我正试图弄清楚在实体上放置自定义操作的位置......
例如,如果我有一个实体Order,在哪里放$order->complete()?或者$order->sendToProduction(),$order->queueForDelivery()?
这些只是示例,我有复杂的实体,我必须对它们执行许多操作.
在控制器?
在实体?
在EntityController中?
还有什么?我必须创建服务吗?实用课程?
为什么会这样呢?我可以预防吗?(除了将它们作为字符串传递外)
var_dump(json_encode([1002.31, 2002.42]));
Run Code Online (Sandbox Code Playgroud)
输出:
string(39) "[1002.3099999999999,2002.4200000000001]"
Run Code Online (Sandbox Code Playgroud) 在Symfony4中,他们选择替换parameters.yml环境变量,如文档和迁移指南中所述:
将与基础架构相关的配置选项定义为环境变量.在开发期间,使用项目根目录下的.env文件来设置它们.
我真的不喜欢这种改变,我没有看到任何优势但只有缺点(例如我们需要重构应用程序,因为现在只允许标量值作为环境变量,你不能在其中托管不同的安装相同的环境等...)
所以我的问题是,是否有可能在Symfony4中保留旧的good parameters.yml文件?如何包含此文件并参考其参数,例如,在doctrine.yml和swiftmailer.yml中?
我在同一台服务器上运行多个 Symfony 应用程序,每个应用程序可能需要不同的时区。
对于 php,可以通过使用不同的 fpm 池并在池配置中设置时区来实现:
php_admin_value[date.timezone] = America/New_York
Run Code Online (Sandbox Code Playgroud)
但对于 MySQL,我需要发出以下语句:
"SET time_zone = 'America/New_York';
Run Code Online (Sandbox Code Playgroud)
作为连接后的第一个查询,或添加到 PDO 构造函数中的 $options 数组:
PDO::MYSQL_ATTR_INIT_COMMAND => "SET time_zone = 'America/New_York';"
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
我找不到如何使用SymbolIcon.Symbol更改appbar图标...
这是为了理解我需要做什么:
if (SecondaryTile.Exists(ItemId))
{
PinToStart.Icon = "UnPin"; //instead of "Pin"
}
Run Code Online (Sandbox Code Playgroud) 我有一个这样的表:
CREATE TABLE `test` (
`id` int(11) NOT NULL,
`settings` json NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `test` (`id`, `settings`) VALUES
('1', '{\"foo\": {\"bar\": 1}}'),
('2', '{\"foobar\": 2}'),
('3', '[]');
Run Code Online (Sandbox Code Playgroud)
我想向一行添加新设置,所以我尝试了JSON_SET:
SELECT *, JSON_SET(settings, '$.newFoo', 10) FROM test;
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,它对第3行不起作用。预期结果当然与第4行相同;[]是 php 中对空数组进行 json 编码的结果(如果该项目没有任何设置)。
可以进行适用于所有情况的单个查询吗?
PS:我需要做的是更新,即UPDATE test SET settings=JSON_SET(...) WHERE id=?;
如何翻译@UniqueEntity 约束中的消息?
我有这种情况:
/**
* @ORM\Entity
* @ORM\Table(name="sites")
* @UniqueEntity(
* fields={"url"},
* message="This url is already registered. Please choose a different url."
* )
*/
class Site
{
Run Code Online (Sandbox Code Playgroud)
如果我保留默认消息(“此值已被使用。”),它会使用一些捆绑字符串自动翻译......但我找不到任何有关如何翻译自定义错误消息的文档。(我试图将该字符串放在默认域中messages,但它没有被翻译)
我有一个带有注释列表的ListView:
<ListView ItemsSource="{Binding Comments}">
<ListView.ItemTemplate>
<DataTemplate>
<Border Background="{Binding User, Converter={StaticResource UsernameToBackgroundColorConverter}}"
Margin="0,5"
HorizontalAlignment="Stretch"
FlyoutBase.AttachedFlyout="{StaticResource FlyoutBase1}"
Holding="BorderCommento_Holding">
<StackPanel>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding User}"
FontSize="20"
Grid.Column="0"
FontWeight="Bold"
Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
<TextBlock HorizontalAlignment="Right"
Text="{Binding DateTime}"
FontSize="20"
Grid.Column="1"
Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
</Grid>
<TextBlock Margin="5,0,5,5"
Text="{Binding Text}"
FontSize="20"
TextWrapping="Wrap"/>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
评论类:
public class Comment
{
public Comment(String id, String user, String text, String date_time)
{
this.Id = id;
this.User = user;
this.Text = text;
this.DateTime …Run Code Online (Sandbox Code Playgroud) 这条简单的路线
$prep = $this->pdo->prepare($sql) or common::error("PDO prepare error: ".$prep->errorInfo()[2]);
Run Code Online (Sandbox Code Playgroud)
正在使用PHP 5.5,但在PHP5.3上失败(即使PHP文档说PDOStatement :: errorInfo在php 5.1+上返回一个数组)说:
解析错误:语法错误,意外'['in ...
我在我的应用程序中多次使用它,不幸的是我无法在这台机器上更新PHP版本.任何解决方法?