小编Als*_*ian的帖子

如何使用Xpath 1.0从XML文档中查找max属性

有没有办法查询XML文档以使用Xpath 1.0返回给定属性的最大值?

例如,有没有办法获得最大ID?

<?xml version="1.0" encoding="utf-8"?>
<library>
        <book id="2" name="Dragon Tatoo"/>
        <book id="7" name="Ender's Game"/>
        <book id="3" name="Catch 22"/>
        <book id="1" name="Lord of the rings"/>
</library>
Run Code Online (Sandbox Code Playgroud)

xml xpath xpath-1.0

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

将哈希表作为参数传递给PowerShell中的函数

我在PowerShell脚本中遇到问题:

当我想将Hashtable传递给函数时,此哈希表不会被识别为哈希表.

function getLength(){
    param(
        [hashtable]$input
    )

    $input.Length | Write-Output
}

$table = @{};

$obj = New-Object PSObject;$obj | Add-Member NoteProperty Size 2895 | Add-Member NoteProperty Count 5124587
$table["Test"] = $obj


$table.GetType() | Write-Output ` Hashtable
$tx_table = getLength $table `Unable to convert System.Collections.ArrayList+ArrayListEnumeratorSimple in System.Collections.Hashtable
Run Code Online (Sandbox Code Playgroud)

为什么?

powershell

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

卷曲选项相当于Net.Webclient的"useDefaultCredentials"

我尝试在php脚本中使用curl访问web:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.google.fr");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

curl_close ($ch);
Run Code Online (Sandbox Code Playgroud)

它返回:

无法连接到www.google.fr端口443:连接被拒绝

这是正常的,我是一个代理,它需要我的Windows凭据(NTLM)允许互联网流量.

在MS Powershell中,这有效:

$request = New-Object System.Net.WebCLient
$request.UseDefaultCredentials = $true
$request.Proxy.Credentials = $request.Credentials
$request.DownloadFile($url, $path)
Run Code Online (Sandbox Code Playgroud)

使用"DefaultCredentials"(= Windows Credentials)并将它们发送到代理允许我访问Web.但我现在不知道它是如何工作的.

如果我使用Firefox导航,Firefox总是会添加一个Proxy-Authorization标头,其值为:Negociate blablablablababalazdlad ...

我想将.NET useDefaultCredentials解决方案转换为cURL,我试过:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.google.fr");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM );

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

curl_close …
Run Code Online (Sandbox Code Playgroud)

curl webclient php-curl

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

扩展EntityType以允许使用AJAX调用设置额外选项

我尝试创建一个扩展核心" 实体 "类型的Symfony Custom 类型.

但是我想在Select2版本4.0.0中使用它(ajax现在可以使用"select"html元素,而不是像以前一样使用隐藏的"输入").

  • 此类型应通过扩展"实体"类型创建空选择而不是完整实体列表.

这通过设置选项(请参阅configureOption)来工作:

'choices'=>array()
Run Code Online (Sandbox Code Playgroud)
  • 通过编辑附加到表单的对象,它应该使用对象的当前数据填充select.我解决了这个问题,但只是为了使用以下buildView方法的视图...

Select2识别html"select"的内容,并使用ajax工作.但是当表单被回发时,Symfony无法识别所选择的选项,(因为不允许这样做?)

Symfony\Component\Form\Exception\TransformationFailedException

    Unable to reverse value for property path "user": The choice "28" does not exist or is not unique
Run Code Online (Sandbox Code Playgroud)

我尝试了几种使用EventListeners或Subscribers的方法,但我找不到工作配置.

使用Select2 3.5.*我解决了表单事件的问题并覆盖了隐藏的formtype,但是这里扩展实体类型要困难得多.

如何构建我的类型以让它管理我的entites的逆向转换?

自定义类型:

<?php
namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Symfony\Component\Form\ChoiceList\View\ChoiceView;

class AjaxEntityType extends AbstractType
{
    protected $router;

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

   /**
    * {@inheritdoc}
    */
    public function buildForm(FormBuilderInterface $builder, array $options)
    { …
Run Code Online (Sandbox Code Playgroud)

symfony jquery-select2

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

在 Doctrine2 中配置原生 Point PostgreSQL 类型

尝试使用 Postgres 执行与此处相同的操作:

http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/

我对“convertToDatabaseValue”函数有问题(请参阅此处:http : //doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types

我的自定义类型:

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class PointType extends Type
{
const POINT = 'point';

public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
    return 'POINT';
}

public function convertToPHPValue($value, AbstractPlatform $platform)
{
    return new Point($value[0],$value[1]);
}

public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
    return "'".$value->getLongitude().','.$value->getLatitude()."'";
}

public function getName()
{
    return self::POINT;
}
}
Run Code Online (Sandbox Code Playgroud)

手动,我可以使用以下 SQL 插入此点:

INSERT INTO points (pointtype,name,score) VALUES ('2.43145,42.84214',"My Place",3241)
Run Code Online (Sandbox Code Playgroud)

但学说 DBAL,创建以下代码:

'INSERT INTO points (pointtype,name,score) VALUES (?,?,?)' with params …
Run Code Online (Sandbox Code Playgroud)

postgresql doctrine symfony doctrine-orm

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