我目前正在重载 SonataUser 注册表格,以便在人们创建帐户时我可以拥有自己的自定义表格。
我已经正确地重载了所有内容(处理程序、表单类型、 Controller 和 Twig 模板)。但是,当我发送表单时,我只取回数据并且没有创建新用户。因此,我进行了调查,发现当我回应这个时
var_dump($this->form->getErrors());
我收到一条错误消息,指出 CSRF token 无效。我正在使用 Symfony 2.4.2 和 sonata user 2.2.x-dev。
我将向您展示我重载的所有类。现在,他们大多是从他们的 parent 那里复制和粘贴的。
这是我的表单处理程序
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace Application\Sonata\UserBundle\Form\Handler;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Form\Handler\RegistrationFormHandler as BaseHandler;
use Symfony\Component\Form\FormInterface;
use FOS\UserBundle\Mailer\MailerInterface;
use FOS\UserBundle\Util\TokenGeneratorInterface;
/**
*
* This file is an adapted version of FOS User Bundle RegistrationFormHandler class
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*/
class RegistrationFormHandler extends BaseHandler
{
protected $request;
protected $userManager;
protected $form;
protected $mailer;
protected $tokenGenerator;
public function __construct(FormInterface $form, Request $request, UserManagerInterface $userManager, MailerInterface $mailer, TokenGeneratorInterface $tokenGenerator)
{
$this->form = $form;
$this->request = $request;
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->tokenGenerator = $tokenGenerator;
}
/**
* @param boolean $confirmation
*/
public function process($confirmation = false)
{
$user = $this->createUser();
$this->form->setData($user);
if ('POST' === $this->request->getMethod()) {
$this->form->bind($this->request);
if ($this->form->isValid()) {
var_dump('working !!');
$this->onSuccess($user, $confirmation);
return true;
}
var_dump($this->form->getErrors());
}
return false;
}
/**
* @param boolean $confirmation
*/
protected function onSuccess(UserInterface $user, $confirmation)
{
if ($confirmation) {
$user->setEnabled(false);
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($this->tokenGenerator->generateToken());
}
$this->mailer->sendConfirmationEmailMessage($user);
} else {
$user->setEnabled(true);
}
$this->userManager->updateUser($user);
}
/**
* @return UserInterface
*/
protected function createUser()
{
return $this->userManager->createUser();
}
}
这是我的表单类型:
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Sonata\UserBundle\Form\Type;
use Entities\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Sonata\UserBundle\Model\UserInterface;
class RegistrationFormType extends AbstractType
{
private $class;
/**
* @var array
*/
protected $mergeOptions;
/**
* @param string $class The User class name
* @param array $mergeOptions Add options to elements
*/
public function __construct($class, array $mergeOptions = array())
{
$this->class = $class;
$this->mergeOptions = $mergeOptions;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, array_merge(array(
'label' => 'form.username',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('email', 'email', array_merge(array(
'label' => 'form.email',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('plainPassword', 'repeated', array_merge(array(
'type' => 'password',
'required' => true,
'options' => array('translation_domain' => 'SonataUserBundle'),
'first_options' => array_merge(array(
'label' => 'form.password',
), $this->mergeOptions),
'second_options' => array_merge(array(
'label' => 'form.password_confirmation',
), $this->mergeOptions),
'invalid_message' => 'fos_user.password.mismatch',
), $this->mergeOptions))
->add('lastName', null, array_merge(array(
'label' => 'form.label_lastname',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('firstName', null, array_merge(array(
'label' => 'form.label_firstname',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('date_of_birth', 'birthday', array_merge(array(
'label' => 'form.label_date_of_birth',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('gender', 'sonata_user_gender', array(
'label' => 'form.label_gender',
'required' => true,
'translation_domain' => 'SonataUserBundle',
'choices' => array(
UserInterface::GENDER_FEMALE => 'gender_female',
UserInterface::GENDER_MALE => 'gender_male',
)
))
->add('phone', null, array_merge(array(
'label' => 'form.label_phone',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('address', null, array_merge(array(
'label' => 'form.address',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('city', null, array_merge(array(
'label' => 'form.city',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
->add('state', 'choice', array_merge(array(
'label' => 'form.state',
'translation_domain' => 'SonataUserBundle',
'multiple' => false,
'expanded' => false
), $this->mergeOptions))
->add('country', 'choice', array_merge(array(
'label' => 'form.country',
'translation_domain' => 'SonataUserBundle',
'multiple' => false,
'expanded' => false
), $this->mergeOptions))
->add('postalCode', null, array_merge(array(
'label' => 'form.postalCode',
'translation_domain' => 'SonataUserBundle',
), $this->mergeOptions))
// ->add('children', 'collection', array_merge(array(
// 'type' => new ChildFormType('Application\Sonata\UserBundle\Entity\User'),
// 'translation_domain' => 'SonataUserBundle',
// 'allow_add' => true,
// 'allow_delete' => true,
// 'by_reference' => false,
// ), $this->mergeOptions))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'intention' => 'registration',
));
}
public function getName()
{
return 'sonata_user_registration';
}
}
这是我的注册 Controller
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Application\Sonata\UserBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AccountStatusException;
use FOS\UserBundle\Model\UserInterface;
/**
* Class SonataRegistrationController
*
* This class is inspired from the FOS RegistrationController
*
* @package Sonata\UserBundle\Controller
*
* @author Hugo Briand <briand@ekino.com>
*/
class RegistrationFOSUser1Controller extends ContainerAware
{
public function registerAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if ($user instanceof UserInterface && 'POST' === $this->container->get('request')->getMethod()) {
$this->container->get('session')->getFlashBag()->set('sonata_user_error', 'sonata_user_already_authenticated');
$url = $this->container->get('router')->generate('sonata_user_profile_show');
return new RedirectResponse($url);
}
$form = $this->container->get('sonata.user.registration.form');
$formHandler = $this->container->get('sonata.user.registration.form.handler');
$confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
$process = $formHandler->process($confirmationEnabled);
var_dump(0);
if ($process) {
var_dump(1);
exit();
$user = $form->getData();
$authUser = false;
if ($confirmationEnabled) {
$this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
$route = 'fos_user_registration_check_email';
} else {
$authUser = true;
$route = $this->container->get('session')->get('sonata_basket_delivery_redirect', 'sonata_user_profile_show');
$this->container->get('session')->remove('sonata_basket_delivery_redirect');
}
$this->setFlash('fos_user_success', 'registration.flash.user_created');
$url = $this->container->get('session')->get('sonata_user_redirect_url');
if (null === $url || "" === $url) {
$url = $this->container->get('router')->generate($route);
}
$response = new RedirectResponse($url);
if ($authUser) {
$this->authenticateUser($user, $response);
}
return $response;
}
$this->container->get('session')->set('sonata_user_redirect_url', $this->container->get('request')->headers->get('referer'));
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
'form' => $form->createView(),
));
}
/**
* Tell the user to check his email provider
*/
public function checkEmailAction()
{
$email = $this->container->get('session')->get('fos_user_send_confirmation_email/email');
$this->container->get('session')->remove('fos_user_send_confirmation_email/email');
$user = $this->container->get('fos_user.user_manager')->findUserByEmail($email);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with email "%s" does not exist', $email));
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:checkEmail.html.'.$this->getEngine(), array(
'user' => $user,
));
}
/**
* Receive the confirmation token from user email provider, login the user
*/
public function confirmAction($token)
{
$user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($token);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with confirmation token "%s" does not exist', $token));
}
$user->setConfirmationToken(null);
$user->setEnabled(true);
$user->setLastLogin(new \DateTime());
$this->container->get('fos_user.user_manager')->updateUser($user);
if ($redirectRoute = $this->container->getParameter('sonata.user.register.confirm.redirect_route')) {
$response = new RedirectResponse($this->container->get('router')->generate($redirectRoute, $this->container->getParameter('sonata.user.register.confirm.redirect_route_params')));
} else {
$response = new RedirectResponse($this->container->get('router')->generate('fos_user_registration_confirmed'));
}
$this->authenticateUser($user, $response);
return $response;
}
/**
* Tell the user his account is now confirmed
*/
public function confirmedAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:confirmed.html.'.$this->getEngine(), array(
'user' => $user,
));
}
/**
* Authenticate a user with Symfony Security
*
* @param \FOS\UserBundle\Model\UserInterface $user
* @param \Symfony\Component\HttpFoundation\Response $response
*/
protected function authenticateUser(UserInterface $user, Response $response)
{
try {
$this->container->get('fos_user.security.login_manager')->loginUser(
$this->container->getParameter('fos_user.firewall_name'),
$user,
$response);
} catch (AccountStatusException $ex) {
// We simply do not authenticate users which do not pass the user
// checker (not enabled, expired, etc.).
}
}
/**
* @param string $action
* @param string $value
*/
protected function setFlash($action, $value)
{
$this->container->get('session')->getFlashBag()->set($action, $value);
}
protected function getEngine()
{
return $this->container->getParameter('fos_user.template.engine');
}
}
这是我的服务:
sonata.user.registration.form.type:
class: Application\Sonata\UserBundle\Form\Type\RegistrationFormType
arguments: [ "%fos_user.model.user.class%"]
tags:
- { name: form.type, alias: sonata_user_registration }
sonata.child.registration.form.type:
class: Application\Sonata\UserBundle\Form\Type\ChildFormType
arguments: [ "%fos_user.model.user.class%"]
tags:
- { name: form.type, alias: sonata_child_registration }
sonata.user.registration.form.handler.default:
class: Application\Sonata\UserBundle\Form\Handler\RegistrationFormHandler
scope: request
public: false
arguments: [@fos_user.registration.form, @request, @fos_user.user_manager, @fos_user.mailer, @fos_user.util.token_generator]
这是我的奏鸣曲用户配置(app/config/config.yml)
sonata_user:
security_acl: false
manager_type: orm # Can be orm for mongodb
table:
user_group: "my_custom_user_group_association_table_name"
impersonating:
route: page_slug
parameters: { path: / }
class: # Entity Classes
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
admin: # Admin Classes
user:
class: Sonata\UserBundle\Admin\Entity\UserAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
group:
class: Sonata\UserBundle\Admin\Entity\GroupAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
profile: # Profile Form (firstname, lastname, etc ...)
form:
type: sonata_user_profile
handler: sonata.user.profile.form.handler.default
name: sonata_user_profile_form
validation_groups: [Profile]
register:
# You may customize the registration forms over here
form:
type: sonata_user_registration
handler: sonata.user.registration.form.handler.default
name: sonata_user_registration_form
validation_groups:
# Defaults:
- Registration
- Default
我的 Twig 渲染:
{% block fos_user_content %}
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="well">
<div class="panel-heading">
<h3>{{ 'title_user_registration'|trans({}, 'SonataUserBundle') }}</h3>
</div>
<div class="panel-body">
<form ng-app="userRegistrationApp" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register form-horizontal">
<h4>{{ 'General'|trans({}, 'SonataUserBundle') }}</h4>
<hr>
<div class="form-group">
{{ form_label(form.username, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.username, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.email, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<br>
<h4>{{ 'form.label_plain_password'|trans({}, 'SonataUserBundle') }}</h4>
<hr>
<div class="form-group">
{{ form_label(form.plainPassword.first, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.second, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<br>
<h4>{{ 'Profile'|trans({}, 'SonataUserBundle') }}</h4>
<hr>
<div class="form-group">
{{ form_label(form.lastName, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.lastName, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.firstName, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.firstName, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.date_of_birth, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.date_of_birth, {'attr': {'class': '' }}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.gender, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.gender, {'attr': {'class': ''}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.phone, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.phone, {'attr': {'class': 'form-control bfh-phone', 'data-country':'sonata_user_registration_form_country'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.address, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.address, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.city, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.city, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.country, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.country, {'attr': {'class': 'form-control bfh-countries', ' data-country':'US'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.state, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.state, {'attr': {'class': 'form-control bfh-states', 'data-country':'sonata_user_registration_form_country'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.postalCode, null, {'label_attr': {'class': 'col-xs-4 control-label'}}) }}
<div class="col-xs-8">
{{ form_widget(form.postalCode, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<br>
{{ form_rest(form) }}
{#<a href="#Children" class="btn btn-link" ng-click="userRegistrationService.addEmptyChild()"><span class="glyphicon glyphicon-plus-sign"></span> {{ 'AddAChildren'|trans({}, 'SonataUserBundle') }}</a>#}
<div class="form-actions">
<button type="submit" class="btn btn-success pull-right">{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock fos_user_content %}
我真的不知道为什么会报错:
array (size=1)
0 =>
object(Symfony\Component\Form\FormError)[1125]
private 'message' => string 'Le jeton CSRF est invalide. Veuillez renvoyer le formulaire.' (length=60)
protected 'messageTemplate' => string 'Le jeton CSRF est invalide. Veuillez renvoyer le formulaire.' (length=60)
protected 'messageParameters' =>
array (size=0)
empty
protected 'messagePluralization' => null
因为我的页面中有 {{form_rest(form)}} 并且存在 token 字段...
更新 我创建了一个 github 存储库,以便可以提取我的配置,以便您自己查看问题。 https://github.com/ima-tech/testSonataUser
最佳答案
好的,当我克隆你的 github 存储库时,我能够通过稍微调整你的服务来消除 CSRF 错误。
parameters:
# osc_default.example.class: OSC\DefaultBundle\Example
services:
# osc_default.example:
# class: %osc_default.example.class%
# arguments: [@service_id, "plain_value", %parameter%]
sonata.user.registration.form.type:
class: Application\Sonata\UserBundle\Form\Type\RegistrationFormType
arguments: [ "%fos_user.model.user.class%"]
tags:
- { name: form.type, alias: sonata_user_registration }
sonata.child.registration.form.type:
class: Application\Sonata\UserBundle\Form\Type\ChildFormType
arguments: [ "%fos_user.model.user.class%"]
tags:
- { name: form.type, alias: sonata_child_registration }
sonata.user.registration.form.handler.default:
class: Application\Sonata\UserBundle\Form\Handler\RegistrationFormHandler
scope: request
public: false
arguments: [@sonata.user.registration.form, @request, @sonata.user.user_manager, @fos_user.mailer, @fos_user.util.token_generator]
你看,在 sonata.user.registration.form.handler.default: 下的参数中,你需要设置 @sonata.user.registration.form 和@sonata.user.user_manager 而不是 @fos_user.registration.form 和 @fos_user.user_manager
关于php - Symfony2 - 过载注册表导致 CSRF 错误(添加了 github repo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22950553/
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。我使用PHP的时间太长了,对它感到厌倦了。我也想学习一门新语言。我一直在使用Ruby并且喜欢它。我必须在Rails和Sinatra之间做出选择,那么您会推荐哪一个?Sinatra真的不能用来构建复杂的应用程序,它只能用于简单的应用程序吗?
我在让asseticsass过滤器与node-sass而不是ruby替代品一起工作时遇到了一些困难。我的config.yml文件中有以下配置:assetic:debug:"%kernel.debug%"use_controller:falsebundles:[]write-to:"%kernel.root_dir%/../web/assets"read_from:"%kernel.root_dir%/../web/assets"node:"%%PROGRAMFILES%%\nodejs\\node.exe"node_paths:["%%USERPROFILE%%\\AppData\
我很确定Ruby有这些(等同于__call、__get和__set),否则find_by将如何在Rails中工作?也许有人可以举一个简单的例子来说明如何定义与find_by相同的方法?谢谢 最佳答案 简而言之你可以映射__调用带有参数的method_missing调用__设置为方法名称以'='结尾的method_missing调用__获取不带任何参数的method_missing调用__调用PHPclassMethodTest{publicfunction__call($name,$arguments){echo"Callingob
Lisp是否适合Web编程/应用程序(交互式),就像ruby和php一样?需要考虑的事情是:易于使用可部署性难度(尤其是对于编程初学者而言)(编辑)在阅读PaulGraham'sessay之后,我特别提到了CommonLisp.将是我的第一门编程语言。在这方面。这样做合适吗?我听说Clojure的宏功能不如CommonLisp的强大,这就是我尝试学习Clojure的原因。它教授编程并且非常强大。 最佳答案 Lisp是一个语系,而不是单一的语言。为了稍微回答您的问题,是的,存在用于各种Lisp方言的Web框架,例如用于Common
项目背景和意义 目的:本课题主要目标是设计并能够实现一个基于微信校园跑腿小程序系统,前台用户使用小程序发布跑腿任何和接跑腿任务,后台管理使用基于PHP+MySql的B/S架构;通过后台管理跑腿的用户、查看跑腿信息和对应订单。意义:手机网络时代,大学生通过手机网购日常用品、外卖外卖、代取快递等已不再是稀奇的事情。此外,不少高校还流行着校园有偿工作,校园跑腿就成了大学生创业服务项目。 因为你在校园里,所以不会有进入的限制。并不是所有的外卖平台都可以随意进入校园,比如小黄和小蓝的双打外卖平台。许多大学禁止送餐进入学校,更不用说送餐进入宿舍了。这一措施使得校园服务市场的竞争相对不
前言 前端时间PHP项目部署升级需要,需要把Laravel开发的项目部署K8s上,下面以laravel项目为例,讲解采用yaml文件方式部署项目。一、部署步骤1.创建Dockerfile文件Dockerfile是一个用来构建镜像的文本文件,在容器运行时,需要把项目文件和项目运行所必须的组件安装其中。#基础镜像FROMphp:7.4-fpm#时区ARGTZ=Asia/Shanghai#更换容器时区RUNcp"/usr/share/zoneinfo/$TZ"/etc/localtime&&echo"$TZ">/etc/timezone#替换成阿里apt-get源RUNsed-i"s@http
关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于StackOverflow来说是偏离主题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,describetheproblem以及迄今为止为解决该问题所做的工作。关闭9年前。Improvethisquestion我对学习Rails很感兴趣已经有一段时间了,我觉得现在正是浸入其中并实际动手实践的好时机。在过去的一周里,我阅读了所有我能找到的关于Ruby和RubyonRails的免费电子书。我刚刚读完RubyEssentials。我也一直在玩htt
在Ruby中(使用Rails,如果相关)将字符串首字母大写的最佳方法是什么?请注意String#capitalize不是我想要的,因为除了将字符串的首字母大写外,此函数还使所有其他字符变为小写(这是我不想要的——我想让它们保持原样):>>"aA".capitalize=>"Aa" 最佳答案 在Rails中你有String#titleize方法:"测试字符串标题化方法".titleize#=>"测试字符串标题化方法" 关于ruby-on-rails-Ruby相当于PHP的ucfirst()
我正在开发一个简单的网站,让管理员提出问题并让用户解决问题。我在管理部分使用ActiveAdmin,在用户解决部分使用简单的AJAX调用。起初尝试通过ActiveAdmin::Devise登录是成功的,但无法退出。我删除了所有cookie,从那时起我无法在没有CSRFtoken真实性异常的情况下进行POST操作。我的application.html.erb头部有正确的meta_tags,声明为jquery_ujs(其他线程说这是一个常见问题),并且在两个POST操作中都存在真实性token。我什至尝试通过skip_before_filter:verify_authenticity_to