我从API端点获取持有者令牌并设置以下内容:
$authorization = "Bearer 080042cad6356ad5dc0a720c18b53b8e53d4c274"
Run Code Online (Sandbox Code Playgroud)
接下来我想使用CURL来访问安全端点,但我不确定如何或在何处设置承载令牌.
我试过这个,但它不起作用:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
Run Code Online (Sandbox Code Playgroud)
编辑:
根据文档,我应该使用持票人令牌:https://apigility.org/documentation/auth/authentication-oauth2
GET /oauth/resource HTTP/1.1
Accept: application/json
Authorization: Bearer 907c762e069589c2cd2a229cdae7b8778caa9f07
Run Code Online (Sandbox Code Playgroud) 是的,所以我花了几天时间更新我的NG2应用程序以使用angular-cli.起初这是一个非常令人沮丧的经历,然而,我真的看到了光明并享受着开发过程.显然,努力工作和思想已被纳入框架.
但我的申请很慢:
根据Pingdom的说法 ,我的应用程序比互联网上所有其他网站的21%快.公平地说,这是一个开箱即用的构建,我相信我可以大大提高速度.
我的最后一个问题是:如何从根本上减少角度网站的大小?
目前,应用程序:fairplay.poker需要7秒才能加载(如果你住在纽约),所以我相信大多数人都会在它有机会加载之前继续前进.
显然,我需要开始一个从根本上提高应用程序速度的旅程,但我需要你的帮助!(因为我不知道我在做什么:)
什么是标准练习,我在哪里开始排序?
进展:
作为建议,我将在这里更新它们.
1. @cyrix建议的生产就绪版本:ng build -prod
Zip文件下降超过一兆,而Pingdom的新统计数据与原始统计数据相比有了很大改进:
2.建议缩小图像尺寸.
有些图像比它们应该有的大一些,因此尺寸减小了.然而,这并不是一个重大改进,这些数据已经将网站提升到前73%的网站,加载时间略快一些.
3. @yurzui建议使用gzip压缩,所以我启用了这个.显然,它正在工作,总文件大小减少了一半以上(609字节),但这并没有显示在Pingdom上.不过我注意到等级有所改善.
我使用这个站点来检查压缩,这个站点向我展示了如何做到这一点,因为Cpanel似乎在从管理启用时不起作用.该站点似乎也是一个很好的gzip压缩资源.
4 @Yuruzi建议实现浏览器缓存.所以我做到了!
真正有趣的是性能等级的改进,那就是摇滚!加载时间快一点,现在该网站占据了74%的前列.根据Yuruzi的建议,我使用这篇文章作为指导.
5感谢#angularjs频道上的@ wafflej0ck.看来我需要提高我已经改变为概述"AddOutputFilterByType DEFLATE*"压缩类型来完成的GZip 这里.
这似乎增加了网站:
6有人建议使用AOT,因此我从这篇文章中删除了一页.
我浏览了大部分文档,然而,我遇到了一个错误的世界,并决定将其留待以后,希望当AOT更稳定时.
我在GitHub上看到Angular-Cli预装了AOT并且上面的文章没有关系.我不确定这是多么真实但是我在编译代码时运行以下命令:ng build --prod --aot
7.调整htaccess文件中的mod_expires.c.
性能等级已显着提高到98%,加载时间现在不到一秒,网站比测试网站的91%快.
该文件目前看起来像这样:
ExpiresActive On ExpiresDefault"access plus 2 days"ExpiresByType image/x-icon"access plus 1 year"ExpiresByType image/jpeg"access plus 1 year"ExpiresByType image/jpg"access plus 1 year"ExpiresByType image/png"access plus 1 year "ExpiresByType image/gif"访问加上1年"ExpiresByType应用程序/ …
我想将自己的自定义CSS添加到我的新Angular CLI应用程序中......
然而,我正在努力让这个工作,并没有太多关于它是如何工作的文档,这使得它有点猜测工作!
在下图中,我将自定义样式表添加到.angular-cli.json文件中,如下所示:
"styles": [
"styles.css",
"app/assets/css/styles.css"
],
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用......
好心提醒!
我正在使用一个小部件,使用json从数据库中提取第三方信息.收集信息后,我计划遍历信息并创建所需的HTML代码,并通过{{variable}}将其插入到模板中
现在我得到了意想不到的结果.当我这样做时,html显示为文本.
以下是该问题的一些sudo代码:
<polymer-element name="loop-element">
<template>
{{customerList}}
</template>
<script>
Polymer('loop-element', {
ready: function() {
this.loadCustomerList();
}
customerList:"Loading customer list...",
loadCustomerList: function() {
CustomerNameArray[] = //Get the array from jSon file
i = 0;
do {
this.customerList = "<div>" + customerNameArray[i] + "</div>";
} while (customerNameArray[i]);
}
});
</script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)
基本上DIV不会被渲染,而是以文本形式打印到屏幕上:
"<div>Name 1</div>" "<div>Name 2</div>" ... n
Run Code Online (Sandbox Code Playgroud)
代替:
Name 1
Name 2
Name n...
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到一个JSBin示例:http://jsbin.com/tituzibu/1/edit
任何人都可以推荐如何输出列表到模板?
我正在使用ZF2 Apigility,我正在为我正在编写的API设置OAuth2工作流程.
到目前为止,我可以得到以下工作:
调用API并获取令牌
{
"access_token": "62f6109dcbce42b38f9117b21529faf30fc0ee86",
"expires_in": 3600,
"token_type": "Bearer",
"scope": null
}
Run Code Online (Sandbox Code Playgroud)现在我知道我需要在下一个请求的标题中使用此标记才能访问我的API.
我只是不确定如何使用PostMan进行此操作?
我有以下代码:
<section class="section1">
//Section one content
</section>
<section class="section2">
<h4>Some Title</h4>
<input type="hidden" class="keys" value="1"/>
<div id="block-close-1"></div>
<div class="block" id="block-1">
//Block content
</div>
</section>
<section class="section3">
//Section3 content
</section>
Run Code Online (Sandbox Code Playgroud)
我想做的是拿一些html并在"block-1"之后插入它
我想添加的HTML如下所示:
<input type="hidden" class="keys" value="2"/>
<div id="block-close-2"></div>
<div class="block" id="block-2">
//Block content
</div>
Run Code Online (Sandbox Code Playgroud)
我试过这个:
var html = '//code as above';
$( "html" ).insertAfter( "#block-1");
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
Uncaught HierarchyRequestError:无法在'Node'上执行'insertBefore':新的子元素包含父元素.
我也试过这个:document.getElementById('#block-4').appendChild(html);
错误:
未捕获的TypeError:无法读取null的属性'appendChild'
将新HTML添加到现有HTML的正确方法是什么?
我正在尝试获取 Angular 2 中的活动链接,以便我可以在我的模板中更新我的 css。
这是我在谷歌的帮助下所做的:
export class AppComponent {
router: Router;
constructor(data: Router) {
this.router = data;
}
isActive(tab): boolean {
if (this.router.currentInstruction && this.router.currentInstruction.component.routeData) {
return tab == this.router.currentInstruction.component.routeData.data['activeTab'];
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我的模板如下:
<li class="some-class" [ngClass]="{active: isActive('some-route')}">
<a [routerLink]="['SomeRoute']" class="menu-item" ><span>Link1</span></a>
</li>
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但我注意到RouterLink 指令具有方法:isRouteActive。
这似乎是使用 this 操作链接类的明智方法。
但是我该如何使用它呢?
我正在尝试访问路线并通过表格工厂发布.路径或帖子包含我需要注入到我的表单中的ID,以便我可以构建一个select语句.
目前我通过控制器使用注入表单
$this->MyForm->get('elementName')->setOptions(array('value_options' =>$myArrayOfOptions));
Run Code Online (Sandbox Code Playgroud)
我的目标是将业务逻辑保持在控制器之外,因此我热衷于使用formFactory,但是我确实需要访问post或route中的ID来实现这一点.
我的Form Factory看起来像这样:
<?php
namespace MyModule\Form;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use AdminLottery\InputFilter\MyFilter;
use AdminLottery\Service\MyService;
class MyFormFactory implements FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(
ServiceLocatorInterface $serviceLocator
)
{
//$serviceLocator is FormElementManager
$realSL = $serviceLocator->getServiceLocator();
//*** I NEED TO ACCESS THE ID / POST HERE TO SEND TO MY FORM
return new MyForm(
$realSL->get('Doctrine\ORM\EntityManager'),
$realSL->get('InputFilterManager')->get(MyFilter::class),
$realSL,
$realSL->get(MyService::class)
);
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗??
我正在使用ApiGility更新购物篮产品和数量,并正在使用Chromes Postman进行测试.
我正在使用PUT方法将表单数据发送到api并继续收到以下错误:
JSON decoding error: Syntax error, malformed JSON
Run Code Online (Sandbox Code Playgroud)
这是我的PostMan设置的屏幕截图:

我已经尝试将Content-Type设置为Text但是然后我得到"指定了无效的内容类型"错误.
有没有办法让PostMan发送Json?
我正在使用x-editable,并想知道如何使用jquery和ajax填充我的select元素.
[编辑 - 为清晰起见]
这是我的代码:
jQuery(document).ready(function() {
//toggle `popup` / `inline` mode
$.fn.editable.defaults.mode = 'popup';
var getSource = function() {
var url = "/api/rpc/payments/status_options";
$.ajax({
type: 'GET',
async: true,
url: url,
dataType: "json",
success: function(responseObject){
}
});
};
//make status editable
$('.payments-click').editable({
type: 'select',
title: 'Select status',
placement: 'right',
value: 2,
source: getSource()
/*
//uncomment these lines to send data on server
,pk: 1
,url: '/post'
*/
});
});
Run Code Online (Sandbox Code Playgroud)
我想获得消息来源:
source: getSource()
Run Code Online (Sandbox Code Playgroud)
从函数但不是100%确定如何从Ajax调用返回数据.
angular ×3
angular-cli ×2
apigility ×2
javascript ×2
jquery ×2
postman ×2
ajax ×1
curl ×1
html ×1
http ×1
oauth-2.0 ×1
php ×1
polymer ×1
x-editable ×1