小编ahm*_*mdy的帖子

FOSUserBundle覆盖映射以删除对用户名的需求

我想在FOSUserBundle中删除对用户名的需求.我的用户将仅使用电子邮件地址登录,并且我已添加实名字段作为用户实体的一部分.我意识到我需要重做整个映射,如此处所述. 我想我已经正确完成了,但当我尝试提交注册表时,我收到错误:

"只有Doctrine映射的字段名称才能被验证为唯一性."

奇怪的是,我没有尝试对用户实体中的任何内容断言唯一约束.

这是我的完整用户实体文件:

 <?php
        // src/MyApp/UserBundle/Entity/User.php

        namespace MyApp\UserBundle\Entity;

        use FOS\UserBundle\Model\User as BaseUser;
        use Doctrine\ORM\Mapping as ORM;
        use Symfony\Component\Validator\Constraints as Assert;

        /**
         * @ORM\Entity
         * @ORM\Table(name="depbook_user")
         */
        class User extends BaseUser
        {
            /**
             * @ORM\Id
             * @ORM\Column(type="integer")
             * @ORM\GeneratedValue(strategy="AUTO")
             */
            protected $id;

            /**
             * @ORM\Column(type="string", length=255)
             *
             * @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"})
             * @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
             */
            protected $firstName;

            /**
             * @ORM\Column(type="string", length=255)
             *
             * @Assert\NotBlank(message="Please enter your last name.", …
Run Code Online (Sandbox Code Playgroud)

doctrine symfony fosuserbundle

7
推荐指数
1
解决办法
1万
查看次数

laravel 4重定向到2个参数的路由

我目前正在尝试使用重定向

public function store($username,$courseId)
{       
        if (Auth::user()->username == $username && Auth::user()->courses()->where('id', '=', $courseId)->first() != null){
        $course = Course::find($courseId);
        $forum = new Forum();
        $forum->description = Input::get('description');
        $forum->course_id   = Input::get('course_id');
        $forum->save();
        return Redirect::to(route('users.courses.forums.index',Auth::user()->username,$course->id));
        }
    return Redirect::to('/');
}
Run Code Online (Sandbox Code Playgroud)

Redirect中的参数不起作用.Store是ForumController中的POST方法.Store收到的参数是正常的,因为我没有验证'if'的问题.我可以创建一个论坛并保存它,但当我尝试重定向时,我有这个错误

Trying to get property of non-object
Run Code Online (Sandbox Code Playgroud)

而users.courses.forums.index是我的URI与Action ForumController @ index的名称.最后一个方法需要2个参数($ username,$ courseid).像这样

public function index($username,$courseId)
{       
        $course = Course::find($courseId);
        $forum = DB::table('forums')->where('course_id',$course->id)->get();
        return View::make('forums.index',compact('course','forum'));    
}
Run Code Online (Sandbox Code Playgroud)

php routing laravel laravel-4

6
推荐指数
1
解决办法
1万
查看次数

在.net core中使用身份验证方案时返回403(forbidden)

我正在使用JWT安全令牌和自定义身份验证方案在我的 Web 应用程序中进行身份验证。

  1. 我在用户登录时生成令牌

  2. 我创建了一个身份验证处理程序,在其中验证所有请求的令牌

身份验证处理程序

public class CustomAuthenticationHandler : AuthenticationHandler<CustomAuthenticationOptions>
{
    public CustomAuthenticationHandler(
        IOptionsMonitor<CustomAuthenticationOptions> options,
        ILoggerFactory logger, 
        UrlEncoder encoder, 
        ISystemClock clock)
    : base(options, logger, encoder, clock)
    {

    }

    protected override Task<AuthenticateResult> HandleAuthenticateAsync()
    {
        try
        {
            Exception ex;
            var key = Request.Headers[Options.HeaderName].First();

            if (!IsValid(key, out ex))
            {

                return Task.FromResult(AuthenticateResult.Fail(ex.Message));
                //filterContext.Result = new CustomUnauthorizedResult(ex.Message);
            }
            else
            {
              
                AuthenticationTicket ticket = new AuthenticationTicket(new ClaimsPrincipal(),new AuthenticationProperties(),this.Scheme.Name);
                return Task.FromResult(AuthenticateResult.Success(ticket));
            }
        }
        catch (InvalidOperationException)
        {
            return Task.FromResult(AuthenticateResult.Fail(""));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

自定义身份验证扩展

public static …
Run Code Online (Sandbox Code Playgroud)

c# authentication jwt .net-core

6
推荐指数
2
解决办法
6193
查看次数

在Laravel中使用自动控制器路线是个坏主意

我来自CodeIgniter到Laravel.

那么,使用自动路由到所有控制器是一个坏主意吗?

Route::controller(Controller::detect());
Run Code Online (Sandbox Code Playgroud)

我应该使用它而不是在routes.php中创建路由吗?

php laravel laravel-3

5
推荐指数
2
解决办法
6488
查看次数

Doctrine Mongodb ODM和DateTime查询

我可以在这个问题上使用一些帮助.我正在使用Symfony2 + mongodb + doctrine创建一个应用程序.我只想使用Doctrine ODM查询过去5分钟内登录过的所有用户.我有一个User集合,其中包含一个名为date_last_login的日期字段.

所以我尝试使用这样的querybuilder:

<?php
// Creating a DateTime object and susbtract 5 min from now
// local time is 15:40:05, timezone: 'Europe/Paris'
$_dateTime = new \DateTime();
$_interval5Min = new \DateInterval('PT5M');
$_dateTime->sub($_interval5Min);

$query = $this->createQueryBuilder('User')
                ->field('date_last_login')->gte($_dateTime)
                ->getQuery();
                ->execute();
Run Code Online (Sandbox Code Playgroud)

当我使用symfony2 profiler查看汇编的查询时,我得到的是:

db.User.find({ "date_last_login": { "$gte": new Date("Fri, 23 Dec 2011 15:30:05 +0100") } });
Run Code Online (Sandbox Code Playgroud)

看起来很好,除了日期提前10分钟而不是5分钟?我只是不明白.如果我转储我的php DateTime对象,日期是正确的:2011-12-23 15:35:05(15:40之前的五分钟).

所以我尝试组装相同的查询而不减少任何分钟,这一次,一切都很好:

<?php
// local time is 15:50:00
$query = $this->createQueryBuilder('User')
            ->field('date_last_login')->gte(new \DateTime())
            ->getQuery();
            ->execute();

// query is ok:
db.User.find({ "date_last_login": { …
Run Code Online (Sandbox Code Playgroud)

php mongodb symfony doctrine-orm doctrine-odm

4
推荐指数
1
解决办法
9590
查看次数

FOSUserBundle在twig表单上使用plainPassword

我正在为新用户注册定义我自己的twig布局,除了FOSUserBundle中的plainPassword字段之外,我已经按照我想要的方式布局了所有内容.

<p class="left">
   {{ form_widget(form.plainPassword) }}
</p>
<div class="clearfix"></div>
Run Code Online (Sandbox Code Playgroud)

上面的代码显示密码和验证块.我想将其分解为form.plainPassword.label,form.plainPassword.field,form.plainPassword2.label和form.plainPassword2.field的4个元素.我无法弄清楚要放入form_label()form_widget()调用的内容.

<p class="left">
   {{ form_label( ??? ) }}
   {{ form_widget( ??? ) }}
</p>
<p class="left">
   {{ form_label( ??? ) }}
   {{ form_widget( ??? ) }}
</p>
<div class="clearfix"></div>
Run Code Online (Sandbox Code Playgroud)

我假设这可以做到.

forms symfony twig fosuserbundle symfony-2.1

4
推荐指数
1
解决办法
5097
查看次数

使用$ db-> insert($ table,$ data)插入zf2; 样式

您好,有没有办法在zf2上使用zf1样式在数据库表中插入数据?

$db->insert('tablename', $data);
Run Code Online (Sandbox Code Playgroud)

$data关联数组在哪里包含(,)

谢谢

php database insert zend-framework2

4
推荐指数
1
解决办法
1万
查看次数

Laravel 4嵌套控制器和路由

是否可以调用嵌套在Laravel 4中的子文件夹中的控件?

我的控制器如下

- Controllers
    - admin
        * AdminController.php
* HomeController.php
* BaseController.php
* ArticleController.php
Run Code Online (Sandbox Code Playgroud)

以下是我的AdminController类的代码:

<?php

class LoginController extends BaseController {

    public function showLogin() 
    {
    return View::make('partials.admin.login');
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的Routes.php文件中,我正在执行以下操作:

Route::get('/admin', 'admin.LoginController@showLogin');
Run Code Online (Sandbox Code Playgroud)

但我得到一个Class not found错误.有什么我想念的,因为我似乎无法从Laravel 4文档中找到解决这个问题的方法.

php laravel laravel-4

4
推荐指数
2
解决办法
9376
查看次数

DQL select语句中的参数(Symfony2/Doctrine)

我试图在DQL-s SELECT部分​​中使用外部参数,但由于错误它不起作用.

我在尝试什么:

$query = $this->getEntityManager()
    ->createQuery("
        SELECT me.column_one, :param_doesnt_work param
        FROM CompanyMyBundle:MyEntity me
        WHERE me.column_one = :param_one
        AND me.column_two = :param_two
    ")->setParameters(array(
        'param_doesnt_work' => 'A static value',
        'param_one' => 'some param',
        'param_two' => 'another param',
    ));
Run Code Online (Sandbox Code Playgroud)

我希望得到两列,结果是'column_one'的值和Select中的param值(在这种情况下为'静态值'作为参数).

我收到以下错误:

错误:期望的IdentificationVariable | ScalarExpression | AggregateExpression | 功能声明| PartialObjectExpression | "("Subselect")"| CaseExpression,得到':param_doesnt_work'

是否有可能在那里使用参数,或者有一个完全不同的解决方案呢?找不到任何例子.

php dql symfony doctrine-orm

3
推荐指数
1
解决办法
2725
查看次数

无法在Ubuntu 14.04中使用sh robomongo.sh运行robomongo.sh

我刚刚从官方网站下载了robomongo64位ubuntu.然后我打开了终端并浏览了文件夹结构并从bin文件夹中执行了命令.

sh robomongo.sh
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误

robomongo.sh: 5: robomongo.sh: Bad substitution
Run Code Online (Sandbox Code Playgroud)

帮我.

提前致谢

mongodb robo3t

3
推荐指数
1
解决办法
5546
查看次数

Symfony Twig模板:字符串比较首先转换为小写

我有以下PHP代码

$option = "yes";
Run Code Online (Sandbox Code Playgroud)

和Twig标签

{% if option == "yes" %}
Run Code Online (Sandbox Code Playgroud)

它工作正常,但如果大写则失败

$option = "YES";
Run Code Online (Sandbox Code Playgroud)

我尝试了以下但它不起作用

{% if option == "yes" | lower %}
Run Code Online (Sandbox Code Playgroud)

还有其他方法吗?似乎无法从Twig文档中找到这个,谢谢!

php symfony twig

2
推荐指数
1
解决办法
3799
查看次数