小编Ger*_*ied的帖子

在静态函数中使用它会失败

我有这个方法,我想使用$ this,但我得到的是:致命错误:当不在对象上下文中时使用$ this.

我怎样才能让它发挥作用?

public static function userNameAvailibility()
{
     $result = $this->getsomthin();
}
Run Code Online (Sandbox Code Playgroud)

php oop static-methods this

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

YouTube Android应用如何选择视频编解码器?

我在YouTube安卓应用中启用了智能手机的统计选项,并在"Vivo V9"和"Nexus 5"设备中播放了相同的视频.

Vivo V9:它以WebM格式播放视频,基本上是"VP8或VP9"编解码器.

Nexus 5:播放MP4格式的视频,基本上是"H264或H265"编解码器.

因此,根据设备YouTube应用选择视频编解码器.

问题:它是如何做的?我在内部知道它使用ExoPlayer播放视频但默认情况下ExoPlayer不提供功能.

youtube android

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

Webpack:排除某些svg文件被打包到app.js中

我有一个使用Webpack构建的Vue.js应用程序.我添加了一个包含数百个SVG标志的库.scss文件非常小 - 标志是文件夹中的单独SVG文件.当我构建时,Webpack将所有SVG文件base64编码到app.js. 在这种特殊情况下,这会产生反效果,因为它会不必要地炸掉我的应用程序的大小.我希望根据需要加载SVG文件夹中的标志,以保持我的应用程序小.

在App.vue中

<style lang="scss">
  @import '~flag-icon-css/sass/flag-icon.scss';
</style>
Run Code Online (Sandbox Code Playgroud)

我的Webpack Config是使用vue-cli创建的.它来自这里:https: //github.com/coreui/coreui-free-vue-admin-template/blob/v1/Vue_Starter/build/webpack.base.conf.js

构建包含img路径中的Flag-SVG文件 - 所以这很好.但是Flag-SVG作为来自webpack的数据加载,而不是直接从img目录加载.

webpack

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

eslint 不允许缩进 4 个空格

我已经为我的项目安装了 eslint 和 eslint-plugin-vue。当我在浏览器中加载项目时,我在控制台中收到以下警告:

http://eslint.org/docs/rules/indent 预期缩进 2 个空格,但发现 4 个
src\_nav.js:2:1

这是我的 _nav.js:

export default {
    items: [{  /*this is line 2 - indented with 4 spaces*/
Run Code Online (Sandbox Code Playgroud)

我试图告诉 lint 我想使用 4 个空格,但我仍然收到警告。我对 .vue 文件有同样的问题。

这是我的 .eslintrc.js:

module.exports = {
    root: true,
    parserOptions: {
        parser: 'babel-eslint'
    },
    env: {
        browser: true,
    },
    extends: [
        // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
        // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
        'plugin:vue/essential',
        // https://github.com/standard/standard/blob/master/docs/RULES-en.md
        'standard'
    ],
    // required to lint *.vue files
    plugins: [
        'vue'
    ], …
Run Code Online (Sandbox Code Playgroud)

eslint vue.js

5
推荐指数
0
解决办法
7244
查看次数

禁止网址的 htaccess 重写规则

我对 htaccess 重写并不陌生,但今天我看到了一个我以前从未见过的规则:

# Access block for folders
RewriteRule _(?:recycler|temp)_/ - [F]
Run Code Online (Sandbox Code Playgroud)

此规则是Typo3 htaccess文件的一部分。

“?:”是什么意思?这是某种反向引用吗?下划线代表什么?非常感谢!

.htaccess mod-rewrite

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

如何用数字替换REGEX - 比如$ 1 <number>

让我们假设我有一个字符串"某事",并想得到"some123".

这将是我的正则表达式: /(some)(thing)/

// Pseudocode
$something = 'something'
$someone = $something.replace(/(some)(thing)/, '$1one') ###works
$some123 = $something.replace(/(some)(thing)/, '$1123') ###fails
Run Code Online (Sandbox Code Playgroud)

$ someone会毫无问题地工作,但是$ 123会失败,因为解释器会查找不存在的组1123.

有任何想法吗?谢谢!

(编辑:我正在使用Powershell,但我认为它在其他语言中也是同样的问题,比如PHP)

regex powershell

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

如何在Symfony中定义默认/其他路由?

我这样定义路线:

// config/routes.yaml

index:
    path: /
    controller: App\Controller\IndexController::index
news:
    path: /news/{slug}
    controller: App\Controller\PageNewsController::show
Run Code Online (Sandbox Code Playgroud)

如果这些路由都不匹配,我想加载默认控制器,或重定向,或其他。但是,如何定义这样的默认路由?

allOthers:
    path: * <-- WHAT#HAS#TO#BE#PUT#HERE
    controller: App\Controller\ElseController::show
Run Code Online (Sandbox Code Playgroud)

我宁愿避免使用注释。

routes symfony symfony4

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

Typo3 - 自己的 viewhelper 在 T3 V8 中转义 HTML

我有一个 viewhelper,它在 Typo3 V7.x 中运行良好,但在 V8.x 中,它的输出不再是纯 html,而是 html 编码的。

简化的viewhelper类:

namespace MyName\Teaserbox\ViewHelpers;
class TeaserboxViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
    public function render ( $html = null ) {
        return "<div><h2>$html</h2></div>"
    }
}
Run Code Online (Sandbox Code Playgroud)

简化的 HTML:

<m:teaserbox><f:cObject typoscriptObjectPath="lib.someHTML"></f:cObject></m:teaserbox>
Run Code Online (Sandbox Code Playgroud)

输出类似于:

&lt;div&gt;&lt;h2&gt;TEST&lt;/h2&gt;&lt;/div&gt;
Run Code Online (Sandbox Code Playgroud)

typo3 viewhelper typo3-8.x

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

将参数传递给 Symfony 的 $cache-&gt;get()

恐怕我有一个 PHP 初学者问题。我正在使用 Symfony 的缓存组件。https://symfony.com/doc/current/components/cache.html

我在接收 2 个参数($url、$params)的函数内部调用缓存对象。

class MainController extends AbstractController {
    public function do($url, $params) {
        $cache = new FilesystemAdapter();
        return $cache->get('myCacheName', function (ItemInterface $c) {
            global $url;
            var_dump($url); // ---> null !!!!
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,我无法访问缓存方法调用内部的函数参数。$url 和 $params 为空。当然,我可以在 MainController 类中使用公共类变量来来回发送变量,但这似乎有点笨拙。

php symfony symfony-cache

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

Symfony SwiftMailer:如果控制器不返回 $this-&gt;render() 响应,则不发送

我有一个 Symfony 项目(非常简化)如下所示:

控制器/MyToolController.php

namespace App\Controller;

use App\Services\ToolsService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class MyToolController extends AbstractController
{
    private $toolsService;


    /**
     * @param ToolsService|null $toolsService
     */
    public function __construct(ToolsService $toolsService = null) {
        $this->toolsService = $toolsService;
    }

    public function run() {
        // some more code here...

        $mailContent = $this->render('site/mail.html.twig', $data)->getContent();
        $this->toolsService->sendMail($from, $to, $bcc, $mailContent, $subject);

        // if I remove the following line, no emails are sent out!
        return $this->render('site/thankyou.html.twig', $data);

    }
}
Run Code Online (Sandbox Code Playgroud)

服务/MyToolService.php

namespace App\Services;

class ToolsService
{

    /** @var \Swift_Mailer */
    private …
Run Code Online (Sandbox Code Playgroud)

php swiftmailer symfony symfony4

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

jQuery承诺(可变数量的承诺)

我有一个脚本加载多个SVG文件,然后应该绘制它们.https://plnkr.co/edit/offqAzlaR1xqGrROQBTc

  var s = Snap("#svg");
  var bigCircle = s.circle(150, 150, 100);

  // Helper to convert Snap.load() into a Promise.
  function loadSVG(url) {
    var deferred = new $.Deferred();
    Snap.load(url, function(x) {
      deferred.resolve( x );
    });
    return deferred.promise();
  }

  // Make an array of Promises.
  var loadPromises = [
    loadSVG('eu.svg'),
    loadSVG('af.svg'),
    loadSVG('am.svg'),
    loadSVG('as.svg'),
  ];

  // Wait for all the Promises to finish.
  $.when( loadPromises ).done(function ( results ) {
    console.log(results); //<-- seems to be a promise again!!!!
    for (var i = …
Run Code Online (Sandbox Code Playgroud)

javascript jquery asynchronous promise

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

D3,打字稿-类型'this'的参数不能分配给类型'BaseType'的参数

我在这里有stackbiltz- https: //stackblitz.com/edit/lable-line-break-vaszab ? file = src/app/app.component.ts

我在Angular应用中有一个d3条形图。

使用创建z轴刻度的函数将x轴标签分为两行

private insertLinebreak(d) {

    let labels = d3.select(this);
    let words = d;
    console.log("Label:", labels.html());
    labels.text('');

    let index = words.indexOf(' ', words.indexOf(' ') + 1)
    let title = words.substr(0, index)
    let subtitle = words.substr(index + 1)

    let tspantitle = labels.append('tspan').text(title)
    let tspansubtitle = labels.append('tspan').text(subtitle)
    tspantitle
      .attr('x', 0)
      .attr('dy', '15')
      .attr('class', 'x-axis-title');
    tspansubtitle
      .attr('x', 0)
      .attr('dy', '16')
      .attr('class', 'x-axis-subtitle');

  };
Run Code Online (Sandbox Code Playgroud)

该函数使用“ this”选择调用函数的“ g”(但在d3中,我认为它选择了整个svg)

这段代码可以在stackblitz中工作,但是在我的实际代码中我得到了错误

Argument of type 'this' is not assignable to parameter of …
Run Code Online (Sandbox Code Playgroud)

d3.js typescript angular

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