小编Kev*_*vin的帖子

安装MAC OS X El Capitan后出错

我的Mac上安装了NodeJS.

$ node -v
v4.2.1
Run Code Online (Sandbox Code Playgroud)

我正在尝试安装凉亭.结果如下:

npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! node v4.2.1
npm ERR! npm  v2.14.7
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir

npm ERR! Error: EACCES: permission denied, rmdir '/usr/local/lib/node_modules/bower'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, rmdir '/usr/local/lib/node_modules/bower']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rmdir',
npm ERR!   path: '/usr/local/lib/node_modules/bower' …
Run Code Online (Sandbox Code Playgroud)

macos node.js npm osx-elcapitan

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

使用curl检查301 http响应

我正在迁移一个网站。我需要将 600 多个旧 url 迁移到具有 symfony 路由和 301 永久重定向的新型 url。

我的网址之一的示例:

redirect_test-url:
    path: /test-url
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /category/test-url
        permanent: true 
Run Code Online (Sandbox Code Playgroud)

重定向似乎有效。但我需要确保我所有的旧网址都使用 301 重定向进行重定向。我想我可以用 php 和curl 编写一个脚本来检查所有的网址。但我不知道如何获得卷曲结果。

这是我的卷曲请求:

curl https://local.dev -k 
Run Code Online (Sandbox Code Playgroud)

但我的终端只是发回 html。

如何获取 http 状态代码响应并将其存储在数据库中?

php curl http symfony

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

以 Angular 显示 ContentFul RichText

我的 Angular 应用中有一个与 Contentful 相关的博客提要。感谢 Contentful javascript sdk。

https://www.contentful.com/developers/docs/javascript/tutorials/using-contentful-in-an-angular-project/

我正在尝试显示标题和文本字段。这是我的代码:

import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs';
import {ContentfulService} from '../../services/contentful/contentful.service';
import { Entry } from 'contentful';

@Component({
  selector: 'app-blog',
  templateUrl: './blog.component.html',
  styleUrls: ['./blog.component.scss']
})
export class BlogComponent implements OnInit {
  private posts: Entry<any>[] = [];

  constructor(private postService: ContentfulService) {}

  ngOnInit() {
    this.postService.getPosts()
      .then(posts => {
        this.posts = posts;
        console.log(this.posts);
      });
  }
}
Run Code Online (Sandbox Code Playgroud)

和 html:

<div *ngFor="let post of posts">
    <a href="#">{{ post.fields.title }}</a>
    <div>{{ post.fields.text …
Run Code Online (Sandbox Code Playgroud)

javascript typescript contentful angular

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

FOSUserBundle.在我的模板中包含登录表单

嗨,我正在尝试在我的自定义模板中包含FOSUser Bundle的登录表单.像那样:

 {% include 'FOSUserBundle:Security:login.html.twig' %}
Run Code Online (Sandbox Code Playgroud)

但我有这个错误: Variable "error" does not exist in FOSUserBundle:Security:login.html.twig at line 7

有没有办法在我的控制器中添加一些内容而不包含模板?

symfony twig fosuserbundle

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

preUpdate Doctrine Listener 中的 Symfony 刷新

嗨,我有一个 prePersist 和 preUpdate 侦听器:

<?php

namespace FM\AppBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use FM\AdminBundle\Entity\Address\DeliveryAddress;

class DeliveryAddressListener
{

    /**
     * @param LifecycleEventArgs $args
     */
    public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if(!$entity instanceof DeliveryAddress){
            return;
        }

        $this->addNameToUser($args);
        $this->addPostalToUser($args);
    }

    /**
     * @param LifecycleEventArgs $args
     */
    public function preUpdate(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if(!$entity instanceof DeliveryAddress){
            return;
        }

        $this->addPostalToUser($args);
    }

    /**
     * @param LifecycleEventArgs $args
     */
    public function addNameToUser(LifecycleEventArgs $args)
    {
        /** @var DeliveryAddress $deliveryAdress */
        $deliveryAdress = $args->getEntity();
        $user = $deliveryAdress->getOwner(); …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

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

Symfony onFlush侦听器

嗨,我有一个onFlush侦听器:

<?php

namespace FM\AppBundle\EventListener;

use FM\AdminBundle\Entity\Address\DeliveryAddress;
use Doctrine\ORM\Event\OnFlushEventArgs;

class DeliveryAddressListener
{
    /**
     * @param OnFlushEventArgs $args
     */
    public function onFlush(OnFlushEventArgs $args)
    {
        $em = $args->getEntityManager();
        $uow = $em->getUnitOfWork();

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            if ($entity instanceof DeliveryAddress) {
                $this->addPostalToUser($entity, $args);
            }
        }
    }

    /**
     * @param DeliveryAddress  $deliveryAddress
     * @param OnFlushEventArgs $args
     */
    public function addPostalToUser(DeliveryAddress $deliveryAddress, OnFlushEventArgs $args)
    {
        $em = $args->getEntityManager();
        $user = $deliveryAddress->getOwner();

        $user->setPostalCode($deliveryAddress->getZipCode());
    }
}
Run Code Online (Sandbox Code Playgroud)

service.yml:

delivery_address.listener:
    class: FM\AppBundle\EventListener\DeliveryAddressListener
    tags:
        - { name: doctrine.event_listener, event: onFlush …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

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

使用 PHP 匿名类进行测试和模拟

我正在尝试使用匿名类测试和模拟一段代码。这是代码:

<?php

namespace App\Service;

use Symfony\Contracts\HttpClient\HttpClientInterface;

class FetchPromoCodeService
{
    private $client;

    public function __construct(HttpClientInterface $client)
    {
        $this->client = $client;
    }

    public function getPromoCodeList(): array
    {
        $response = $this->client->request(
            'GET', 'https://xxxxxxxxx.mockapi.io/test/list'
        );

        return $response->toArray();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的测试类:

<?php

namespace App\Tests\Service;

use App\Service\FetchPromoCodeService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\JsonResponse;

class FetchPromoCodeServiceTest extends TestCase
{

    public function testGetPromoCodeList()
    {
        $fetchPromoCodeService = new class () extends FetchPromoCodeService {
            public $client;

            public function __construct($client)
            {
                $this->client = (new JsonResponse(['a' => 1, 'b' => 2]))->getContent();
                parent::__construct($client);
            }
        }; …
Run Code Online (Sandbox Code Playgroud)

php phpunit unit-testing symfony php-7

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

为每个终端加载.bash_profile

我在Max OS X的.bash_profile中设置了一些别名。它可以工作,但是当我打开一个新标签时,我总是必须使用以下命令加载.bash_profile文件:

source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

即使我重新启动Mac或Linux计算机,我如何使它在打开的每个终端上也都能正常工作?

unix macos bash

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