当我做一个简单的查询,比如查找所有用户时,它返回一个空数组.
$users = $em->getRepository('MyApp\\Model\\Entity\\User')->findAll();
但是,当我使用PDO手动连接到我的数据库时,它会找到数据.我正在使用ArrayCache方法,以确保它与没有文件系统的GAE无关.GAE文档说你可以使用sys_get_temp_dir()
,所以我不认为这是我的代理.我不知道为什么Doctrine什么都没有返回,也没有抛出任何错误.
这是我的应用程序的引导程序文件:
<?php
$baseDir = dirname(dirname(__FILE__));
define('TIMEZONE_OFFSET', \MyApp\Library\Date::getMyTimezoneOffset());
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
// globally used cache driver, in production use APC or memcached
$cache = new Doctrine\Common\Cache\ArrayCache;
// standard annotation reader
$annotationReader = new AnnotationReader;
AnnotationReader::addGlobalIgnoredName('dummy');
AnnotationRegistry::registerFile(__DIR__ . "/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
AnnotationRegistry::registerFile(__DIR__ . "/Gedmo/Timestampable/Mapping/Driver/Annotation.php");
AnnotationRegistry::registerAutoloadNamespace("\\MyApp\\Model\\Entity", $baseDir);
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader(
$annotationReader, // use reader
$cache, // and a cache driver
$debug = LOCAL
);
// create a driver chain for metadata reading
$driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain(); …
Run Code Online (Sandbox Code Playgroud) 我意识到你永远不应该禁用一个元素并且也需要它,因为如果它被禁用,用户怎么能使它有效?
但是,我有一些<select>
产品,我希望我的用户可以选择.当他们选择其中一种产品时<select>
,仅当产品具有一个或多个型号时,才会填充,启用和需要产品的其他产品.否则,禁用并清空模型选择.
虽然我喜欢认为我的代码是完美的,我可以做到这样,模型下拉列表永远不会被禁用并同时需要,但我并不完美.那么,表单是否能够以<select>
禁用和必需的形式提交?
来自w3.org:
约束验证:如果元素是必需的,并且其值IDL属性适用并且在模式值中,并且元素是可变的,并且元素的值是空字符串,则该元素正在丢失.
查看具体的"可变"意味着什么.
表单控件可以指定为可变的.
注意:这决定了(通过本规范中的定义和要求依赖于是否指定了元素)用户是否可以修改表单控件的值或检查,或者控件是否可以自动预填充.
选择没有值,因此由它的选项决定.
select元素没有值; 其选项元素的选择性是用来代替的.
所以,我认为这意味着如果一个<select>
元素被禁用并且需要,那么表单可以被认为是有效的吗?
我有两个实体Order
和Shipment
. 每个订单有一个发货,反之亦然。我正在尝试查询待处理的订单。以下是标准:
这是我提出的查询:
<?php
use Doctrine\ORM\EntityRepository;
class OrderRepository extends EntityRepository
{
public function findPending($id)
{
return $this->createQueryBuilder('o')
->addSelect('s')
->leftJoin('MyApp\\Model\\Entity\\Shipment', 's')
->orderBy('o.date_sent', 'DESC')
// Order has been sent
->where($qb->expr()->neq('o.date_sent',':date_sent'))
->setParameter('date_sent', '0000-00-00 00:00:00')
// Order was not cancelled
->where($qb->expr()->eq('o.date_cancelled',':date_cancelled'))
->setParameter('date_cancelled', '0000-00-00 00:00:00')
// Order does not have a shipment
->andWhere($qb->expr()->isNull('s.order'))
// OR Shipment has not been sent
->orWhere($qb->expr()->neq('s.date_sent', ':ship_date_sent'))
->setParameter('ship_date_sent', '0000-00-00 00:00:00')
// AND Shipment has not been cancelled …
Run Code Online (Sandbox Code Playgroud) 我想将多个数组合并在一起,同时优先考虑第一个数组中的值,并且只有唯一值.是否有一个更快的方法比使用array_merge()
,array_unique()
以及+
运营商?
function foo(...$params) {
$a = [
'col1',
'col2_alias' => 'col2',
'col3'
];
$merged = array_merge($a, ...$params);
$unique = array_unique($merged);
print_r($merged);
print_r($unique);
print_r($a + $unique);
}
foo(
['col4', 'col5_alias' => 'col5', 'col6'],
['col7', 'col1', 'col5_alias' => 'col5', 'col2_alias' => 'col10']);
Run Code Online (Sandbox Code Playgroud)
只是合并数组会给我重复的值,并覆盖第一个数组中的值:
Array
(
[0] => col1 // duplicate
[col2_alias] => col10 // overwritten
[1] => col3
[2] => col4
[col5_alias] => col5
[3] => col6
[4] => col7
[5] => col1 // duplicate
) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取company_id
没有公司级别注释的's列表。但是,该公司可能有位置级别的注释。
company
-------------------------
company_id name deleted
1 Foo 0
2 Bar 0
3 Baz 0
location
-----------------------
location_id company_id
6 1
7 2
8 3
note
-----------------------------------------
note_id company_id location_id deleted
10 2 6 0 // location-level note
11 1 7 0 // location-level note
12 null 8 0 // location-level note
13 2 null 0 // company-level note
Run Code Online (Sandbox Code Playgroud)
我希望我的结果表是这样的:
company_id name
1 Foo
3 Baz
Run Code Online (Sandbox Code Playgroud)
更新
Foo
/company_id = 1
没有公司级别的注释,因为该注释还有一个location_id
,这使其成为位置级别的注释。公司级注释是仅链接到公司(而不是位置)的注释。
更新结束
我试过做这样的事情,但它返回一个空集,所以我不确定它是否有效,并且没有任何公司没有公司级别的注释或者我做错了什么。
SELECT …
Run Code Online (Sandbox Code Playgroud) 我的 CSS 文件在 FireFox (52.0.1) 中正确加载。它们列在“样式编辑器”选项卡中,但不在“网络监视器”选项卡中。无论我在“网络监视器”选项卡中单击“全部”还是“CSS”,都不会显示任何 CSS 文件。
我将 css 文件包含在其中,如下<head>
所示:
<link rel="stylesheet" type="text/css" href="https://{path}/css/print.css" media="print">
<link rel="stylesheet" type="text/css" href="https://{path}/plugins/components/jquery-ui/themes/base/all.css" media="all">
Run Code Online (Sandbox Code Playgroud)
考虑到有 CSS 选项,我假设它们应该显示在“网络监视器”选项卡中,那么会出现什么情况呢?
我正在尝试暂时允许脚本使用allow_url_fopen
和rename
功能。我可以只使用一个功能,但不能同时使用两个功能。
像这样:
php -d allow_url_fopen=on rename=on <file>
Run Code Online (Sandbox Code Playgroud)
我正在使用PHP 5.6
显然rename()
是在disable_functions
我的php.ini文件中(而在该文件allow_url_fopen
之外已关闭),所以我假设该-d
选项不会更改disable_functions
指令的设置。
因此,原始问题仍然存在,而新问题是:
可以使用命令行工具启用禁用的功能吗?还是我必须重新定义整个disable_functions
指令(如果可能)?
这适用于我的情况:
php -d disable_functions=fn1,fn2,etc -r 'ini_set("allow_url_fopen", "1");' <file> <args>
Run Code Online (Sandbox Code Playgroud)
您不能使用ini_set()
更改disable_functions
指令。如果您的php.ini文件中还有其他指令无法更改,ini_set()
那么我不知道该如何解决。我的问题已解决,尽管原始问题尚未得到解答。
几个小时前,我确实在工作.不知道我做了什么搞砸了,如果有的话.我试图使用file_put_contents()到我的临时目录中的test.txt文件来测试一些东西.我不能使用print_r()或echo,因为有时它是我正在测试的ajax调用.我一直遇到的错误是:
Warning: file_put_contents(temp/test.txt): The local filesystem is readonly, open failed in sub-dirs.../request.php on line 62
Warning: file_put_contents(temp/test.txt): failed to open stream: No such file or directory in sub-dirs.../request.php on line 62
Run Code Online (Sandbox Code Playgroud)
我不是在制作.这是本地的,根据文档,这应该工作:
在开发Web服务器中存储数据
Google App Engine for PHP支持通过PHP的流API读取和写入Google云端存储.开发人员可以通过将其指定为支持PHPs Streams实现的任何PHP函数的URI(例如fopen(),fwrite()或get_file_contents())来读取和写入Google云存储中的对象.
在开发服务器中,当指定Google云存储URI时,我们通过读取和写入用户本地文件系统上的临时文件来模拟此功能.这些文件在请求之间保留,允许您在将代码部署到App Engine之前测试本地开发环境中的功能.
在PHP开发服务器中,像'fopen()这样的流调用,'gs://'url上的file_get_contents()通过读写本地文件系统来模拟.
我非常沮丧,所以任何帮助都非常感激.将upvote.
php ×5
doctrine-orm ×2
mysql ×2
sql ×2
arrays ×1
command-line ×1
css ×1
distinct ×1
file-writing ×1
firefox ×1
form-submit ×1
forms ×1
html5 ×1
ini ×1
left-join ×1
orm ×1
pdo ×1
select ×1
validation ×1