小编Dev*_*key的帖子

类xx中的注释@Doctrine\ORM\Mapping不存在,或者无法加载

执行时php app/console doctrine:generate:entities etBundle:Users我收到此错误消息:

[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Doctrine\ORM\Mapping" in class Ampisoft\Bundle\etrackBundle\Entity\Users does not exist, or could not be auto-loaded.
Run Code Online (Sandbox Code Playgroud)

我的实体类如下:

namespace Ampisoft\Bundle\etrackBundle\Entity;


 use Doctrine\ORM\Mapping as ORM;

 /**
 * @ORM/Entity
 * @ORM/Table(name="users")
 */
class Users
{
/**
 * @ORM/Column(type="integer")
 * @ORM/ID
 * @ORM/GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=25, unique=true)
 */
protected $username;

/**
 * @ORM\Column(type="string", length=64)
 */
protected $password;


/**
 * @ORM\Column(name="is_active", type="boolean")
 */
private $isActive;

/**
 * @ORM\Column(type="string", length=60, unique=true)
 */
protected $email;

/** …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony doctrine-orm

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

有条件地在 twig 2 中定义一个块

所以这是用例:

  • 在动态页面结构中渲染登录表单块,但前提是用户未经身份验证
  • 如果未经身份验证,则不得定义块(以保留动态页面结构)

树枝 2.2
交响乐 3.2


在基本模板中,我仅渲染已定义的块(不是“非空”)

base.html.twig

{% if block('left_sidebar') is defined %}
      <div class="col-md-2">
           {{- block('left_sidebar') -}}
      </div>
      <div class="col-md-10">
{% else %}
      <div class="col-md-12">
{% endif %}
Run Code Online (Sandbox Code Playgroud)

索引.html.twig

为了使上述工作正常,块根本无法定义(这完全是设计的)。无论如何,以下内容都会渲染该块,但我无法弄清楚为什么。

{% if not is_granted('IS_FULLY_AUTHENTICATED') %}
    {% block left_sidebar %}
        {% include ':blocks:block__login.html.twig' %}
    {% endblock %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)

我想知道这是否不起作用,因为与基本模板代码起作用的原因相同。也就是说,块在运行时之前编译,条件语句在运行时执行。

任何人都可以确认我是对的吗?或者如果我错了请纠正我?

编辑

我尝试将条件的结果强制为 true 和 false,并且在任何一种情况下都会呈现该块。

templating symfony twig

5
推荐指数
1
解决办法
3223
查看次数

计算评分系统的平均值

我想计算评级系统的平均值,但我在 innodb 中有普通表,在 json 中有一个列,名称为:“评论”,结构如下:

{"comments": 
    [
        {"name": "Jonh", "text": "nice phone", "star": 4}, 
        {"name": "igon", "text": "not good", "star": 2}, 
        {"name": "marco", "text": "i not like this", "star": 3},
        {"name": "david", "text": "good product", "stelle": 5}
    ]
}
Run Code Online (Sandbox Code Playgroud)

现在我需要计算平均星级。它是在 sql 中还是在 php 中?在 sql 中我不知道如何,在 php 中我有查询只提取全明星的问题,例如:

$reviews_nn = $rowprod["reviews"];
$reviews = json_decode($reviews_nn,true);
$max = 0;
$n = 0;
foreach ($reviews[comments][star] as $rate => $count) {
    echo 'Seen ', $count, ' ratings of ', $rate, "\n";
    $max += $rate …
Run Code Online (Sandbox Code Playgroud)

php mysql rating

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

Trying to get a token not currently working

I am trying to put a JWT Auth to access my API : /api/docs But I am currently getting an error while trying to get the token with this command :

curl -X POST -H "Content-Type: application/json" http://localhost/login_check -d '{"username":"johndoe","password":"test"}'
Run Code Online (Sandbox Code Playgroud)

Of course I replace username and password

Signature key "/var/www/config/jwt/private.pem" does not exist or is not readable. Did you correctly set the "lexik_jwt_authentication.signature_key" configuration key? (500 Internal Server Error)

security.yaml

    firewalls:
        login:
            pattern:  ^/login
            stateless: true
            anonymous: true
            provider: fos_userbundle_2 …
Run Code Online (Sandbox Code Playgroud)

token symfony jwt api-platform.com

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