在Symfony2应用程序的路由配置中,我可以引用这样的文件:
somepage:
prefix: someprefix
resource: "@SomeBundle/Resources/config/config.yml"
Run Code Online (Sandbox Code Playgroud)
有没有办法在控制器或其他PHP代码中访问相对于bundle的文件?特别是,我正在尝试使用Symfony\Component\Yaml\Parser对象来解析文件,我不想绝对引用该文件.基本上,我想这样做:
$parser = new Parser();
$config = $parser->parse( file_get_contents("@SomeBundle/Resources/config/config.yml") );
Run Code Online (Sandbox Code Playgroud)
我已经检查了Symfony\Component\Finder\Finder类,但我认为这不是我想要的.有任何想法吗?或者我可能完全忽略了这样做的更好方法?
如何使用Doctrine在Symfony2中创建自定义SQL查询?或者没有学说,我不在乎.
不这样工作:
$em = $this->getDoctrine()->getEntityManager();
$em->createQuery($sql);
$em->execute();
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在编写一个脚本,该脚本基于使用连接在一起的多个表的查询生成报告.脚本的其中一个输入将是报告所需的字段列表.根据请求的字段,可能不需要某些表.我的问题是:如果在SELECT或WHERE子句中没有引用连接,是否存在[重要]性能损失?
请考虑以下表格:
mysql> SELECT * FROM `Books`;
+----------------------+----------+
| title | authorId |
+----------------------+----------+
| Animal Farm | 3 |
| Brave New World | 2 |
| Fahrenheit 451 | 1 |
| Nineteen Eighty-Four | 3 |
+----------------------+----------+
mysql> SELECT * FROM `Authors`;
+----+----------+-----------+
| id | lastName | firstName |
+----+----------+-----------+
| 1 | Bradbury | Ray |
| 2 | Huxley | Aldous |
| 3 | Orwell | George |
+----+----------+-----------+
Run Code Online (Sandbox Code Playgroud)
是否
SELECT
`Authors`.`lastName`
FROM …Run Code Online (Sandbox Code Playgroud) 我正在使用RESTAPI与django服务器通信php客户端.我发布了json数据.php代码是
$arr=array("username"=>"dtthtdas45",
"password"=>"123456",
"email"=>"ramg@ram.com",
"is_active"=>"1",
"is_staff"=>"1",
"is_superuser"=>"1",
"promo_code"=>"1212121",
"gender"=>"m",
"birth_year"=>"1991",
"zip"=>"77707",
"first_name"=>"john",
"last_name"=>"doe",
"current_state"=>"1"
);
echo $data_string= json_encode($arr);
$ch = curl_init('http://localhost:8000/api/ecp/user/?format=json');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
如何仅使用命令行调用相同的URL?
我尝试了下面的内容
curl -H 'Content-Type: application/json' -X POST -d '{"username": "dtthtdas45", "password": "123456","email":"email@email.com","is_active":"1","is_staff":"1","is_superuser",promo_code":"1212121","gender":"m","birth_year":"1991","zip":"77707","first_name":"john","last_name":"doe","current_state":"1"}' http://localhost:8000/api/ecp/user/?format=json
Run Code Online (Sandbox Code Playgroud)
但没有运气,它显示了下面的错误
curl: (6) Couldn't resolve host 'application'
curl: (6) Couldn't resolve host 'dtthtdas45,'
curl: (6) Couldn't resolve host 'password:'
Run Code Online (Sandbox Code Playgroud) 我需要在我的帮助器中使用doctrine,我试着在控制器中像我一样正常使用:
$giftRepository = $this->getDoctrine( )->getRepository( 'DonePunctisBundle:Gift' );
Run Code Online (Sandbox Code Playgroud)
但这给了我:
致命错误:调用未完成的方法DONE\PUNCTISBUNDLE\HELPER\UTILITYHELPER :: GETDOCTRINE()/VAR/WWW/VHOSTS/PUNCTIS.COM/HTTPDOCS/SRC/DONE/PUNCTISBUNDLE/HELPER/UTILITYHELPER.PH
我在这里失踪了什么?
编辑:
服务文件
services:
templating.helper.utility:
class: Done\PunctisBundle\Helper\UtilityHelper
arguments: [@service_container]
tags:
- { name: templating.helper, alias: utility }
Run Code Online (Sandbox Code Playgroud)
第一行辅助文件
<?php
namespace Done\PunctisBundle\Helper;
use Symfony\Component\Templating\Helper\Helper;
use Symfony\Component\Templating\EngineInterface;
class UtilityHelper extends Helper {
/*
* Dependency injection
*/
private $container;
public function __construct( $container )
{
$this->container = $container;
}
Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
的index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form>
<button id="getInfoButton1"></button>
<input type="button" id="getInfoButton2"></input>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
随附JavaScript文件:
的script.js
window.onload = initAll;
var req;
function initAll()
{
document.getElementById("getInfoButton1").onclick = getInfo;
document.getElementById("getInfoButton2").onclick = getInfo;
}
function getInfo()
{
req = new XMLHttpRequest();
var URL = "index.html";
req.open("GET", URL, true);
req.onreadystatechange = whatsTheStatus;
req.send(null);
}
function whatsTheStatus()
{
if (req.readyState != 4) { return; }
alert(req.status);
}
Run Code Online (Sandbox Code Playgroud)
(我已经减少了很多代码,但这个例子仍然突出了错误)
问题是这样:当你加载它,并单击两个按钮时,第一个将显示状态0,而第二个显示状态为200.
当然,我期望两者都显示 …
我如何计算包含在变量中的类项的元素
到目前为止http://jsfiddle.net/jGj4B/
var post = '<div/><div class="item"></div><div class="item"></div><div class="item"></div><div class="item"></div>';
alert($(post).find('.item').length);? // i have tried .size() in place of .length
Run Code Online (Sandbox Code Playgroud) 我有一个Python命令,生成字符串的SHA-1哈希的URL安全base-64编码:
>>> import base64
>>> import sha
>>> base64.urlsafe_b64encode((sha.new("abc").digest()))
'qZk-NkcGgWq6PiVxeFDCbJzQ2J0='
Run Code Online (Sandbox Code Playgroud)
我想在bash shell中做同样的事情,但我遇到了问题:
me:~$ echo -n "abc" | sha1sum | sed 's/ .*//'
a9993e364706816aba3e25717850c26c9cd0d89d
me:~$ echo -n "abc" | sha1sum | sed 's/ .*//' | base64
YTk5OTNlMzY0NzA2ODE2YWJhM2UyNTcxNzg1MGMyNmM5Y2QwZDg5ZAo=
Run Code Online (Sandbox Code Playgroud)
我怀疑这是因为sha1sum的打印方式(以十六进制格式).我认为base64正在读取40个字节,但它实际上应该只读取20个.我已经尝试通过iconv进行管道传输,但是没有成功:
me:~$ echo -n "abc" | sha1sum | sed 's/ .*//'
a9993e364706816aba3e25717850c26c9cd0d89d
me:~$ echo -n "abc" | sha1sum | sed 's/ .*//' | base64
YTk5OTNlMzY0NzA2ODE2YWJhM2UyNTcxNzg1MGMyNmM5Y2QwZDg5ZAo=
Run Code Online (Sandbox Code Playgroud)
我应该在这做什么来获得我期望的输出?
在此先感谢您的帮助!