我有这个方法,我想使用$ this,但我得到的是:致命错误:当不在对象上下文中时使用$ this.
我怎样才能让它发挥作用?
public static function userNameAvailibility()
{
$result = $this->getsomthin();
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用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目录加载.
我已经为我的项目安装了 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) 我对 htaccess 重写并不陌生,但今天我看到了一个我以前从未见过的规则:
# Access block for folders
RewriteRule _(?:recycler|temp)_/ - [F]
Run Code Online (Sandbox Code Playgroud)
此规则是Typo3 htaccess文件的一部分。
“?:”是什么意思?这是某种反向引用吗?下划线代表什么?非常感谢!
让我们假设我有一个字符串"某事",并想得到"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)
我这样定义路线:
// 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)
我宁愿避免使用注释。
我有一个 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)
输出类似于:
<div><h2>TEST</h2></div>
Run Code Online (Sandbox Code Playgroud) 恐怕我有一个 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 类中使用公共类变量来来回发送变量,但这似乎有点笨拙。
我有一个 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) 我有一个脚本加载多个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) 我在这里有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) php ×3
symfony ×3
symfony4 ×2
.htaccess ×1
android ×1
angular ×1
asynchronous ×1
d3.js ×1
eslint ×1
javascript ×1
jquery ×1
mod-rewrite ×1
oop ×1
powershell ×1
promise ×1
regex ×1
routes ×1
swiftmailer ×1
this ×1
typescript ×1
typo3 ×1
typo3-8.x ×1
viewhelper ×1
vue.js ×1
webpack ×1
youtube ×1