要简单地检查数组是否包含某个值,我会这样做:
{% if myVar in someOtherArray|keys %}
...
{% endif %}
Run Code Online (Sandbox Code Playgroud)
但是,我的阵列是多维的.
$tasks = array(
'someKey' => 'someValue',
...
'tags' => array(
'0' => array(
'id' => '20',
'name' => 'someTag',
),
'1' => array(
'id' => '30',
'name' => 'someOtherTag',
),
),
);
Run Code Online (Sandbox Code Playgroud)
我想要的是能够检查是否$tasks['tags']有标签ID 20.我希望我不会混淆使用PHP数组格式.
我正在从w3schools的PHP教程学习PHP.
在学习PHP时,我遇到了预定义全局变量的概念,即Superglobals.
为了更好地理解"Superglobals",我写了下面的代码并在我的本地机器上的浏览器中执行它(ielocalhost):
<!DOCTYPE html>
<html>
<body>
<?php
echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在浏览器中得到了以下输出:
Array
(
[_GET] => Array
(
)
[_POST] => Array
(
)
[_COOKIE] => Array
(
[toWorkNormally] => 1
)
[_FILES] => Array
(
)
[GLOBALS] => Array
*RECURSION*
)
Run Code Online (Sandbox Code Playgroud)
以上输出在我的脑海中产生了许多疑点如下:
$GLOBALS,
$_SERVER, $_REQUEST, $_POST, $_GET, $_FILES, $_ENV, $_COOKIE和
$_SESSION那么我的疑问是什么呢,从预定的整个数组的数组元素
$GLOBALS即 [_GET], [_POST], [_COOKIE], [_FILES]意味着他们有超自然的独立存在吗?[toWorkNormally] => 1上面的数组输出是什么意思?大约两周前我最近问了一个类似的问题,但是我没有看到我的问题以我需要的方式运行.
我有一个从2个表中选择的查询; 门票和回复.我正在从故障单表中选择信息,并且我从回复表中选择了存储有票证ID的信息.这就是我的问题.
我的查询只显示回复超过0的票证,但我需要它才能显示票证信息,即使它没有任何回复.
我想知道(如果可能的话)是否有任何方法可以解决我的问题,如果有办法让它比我现在拥有它更简单.
现在它有点乱,但这是我的代码,用于查询和显示故障单和回复.
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = trim($_GET['id']);
$i = "";
$ticket = $db->conn->query("
SELECT * FROM tickets
INNER JOIN replies ON tickets.id = '$id'") or die(mysqli_error($db->conn));
while($rows = $ticket->fetch_assoc()) {
$i++;
if($_SESSION['ticket_username'] == $rows['client']) {
if($i <= 1) {
$status = $rows['status'];
echo '
<h3>'.$rows['subject'].'</h3><hr>
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><small>Created by '.$rows['client'].', '.$timeAgo->inWords($rows['created_at']).'</small></h3>
</div>
<div class="panel-body">'.nl2br($rows['message']).'</div>
</div>
';
}
echo '
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title"><small>Reply from '.$rows['reply_username'].', '.$timeAgo->inWords($rows['reply_time']).'</small></h3>
</div> …Run Code Online (Sandbox Code Playgroud) 曾几何时,在黑暗的深渊中,有一些人在Symfony的土地深处,有一个沮丧的程序员.他尝试过并试过但不知何故,邪恶的教义一次又一次地被打击.还有恶棍Joins,Associative tables并One-to-Many/Many-to-One给他一个艰难的时刻.然后,在一个傍晚StackOverflow,它的社区来救援.
足够的童话故事.我的问题是我有三个表应该都引用同一个表来获取附件.
- Mail
- Order
- Ticket
Run Code Online (Sandbox Code Playgroud)
这三个实体中的每一个都可以有附件.所以我创建了一个附件实体.
现在,我的数据库包含以下内容
Table: mails
- id
- from
- to
- message
Table attachments
- id
- name
- path
Table: orders
- id
- ...
Table: tickets
- id
- name
- description
- ...
Table attachment_associations
- id
- type
- parent_id
- attachment_id
Run Code Online (Sandbox Code Playgroud)
我想做的是能够将订单,票据和邮件映射到相同的附件表.
但是,我坚持如何在学说中做到这一点.
我尝试使用以下方法.这确实得到了我正在寻找的记录.但我不知道如何使用此方法自动创建,更新或删除关联表(连接表)中的记录.
/**
* @ORM\ManyToMany(targetEntity="\...\...\Entity\Attachment")
* @ORM\JoinTable(name="attachment_associations",
* joinColumns={@ORM\JoinColumn(name="parentId", referencedColumnName="id")},
* inverseJoinColumns={
* @ORM\JoinColumn(name="attachmentId", referencedColumnName="id") …Run Code Online (Sandbox Code Playgroud) 我正在用 PHP 开发一个应用程序,我需要使用日期和工作日的数字表示。
我尝试了以下方法:
$today = date("Y-m-d");
$number = date('N', strtotime($today));
echo "Today: " . $today . " weekday: " . $number . "<br>";
$today = strtotime($today);
$tomorrow = strtotime($today);
$tomorrow = strtotime("+1 day", $today);
$number2 = date('N', strtotime($tomorrow));
echo "Tomorrow: " . date('Y-m-d', $tomorrow) . " weekday: " . $number2 . "<br>";
Run Code Online (Sandbox Code Playgroud)
Today: 2016-11-11 weekday: 5
Tomorrow: 2016-11-12 weekday: 4
Run Code Online (Sandbox Code Playgroud)
这是不对的,因为明天的工作日应该是 6 而不是 4。
有人可以帮我吗?
我在 symfony 中有这个简单的命令:
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AuctionEndCommand extends Command
{
protected function configure()
{
error_log(print_r('test',true), 3, "/tmp/error.log");
$this->setName('desktop:auction_end')->setDescription('Execute when auction is end.')->setHelp("Identify winners for auctions");
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// outputs multiple lines to the console (adding "\n" at the end of each line)
$output->writeln([
'User Creator',
'============',
'',
]);
// outputs a message followed by a "\n"
$output->writeln('Whoa!');
// outputs a message without adding a "\n" at the end of the …Run Code Online (Sandbox Code Playgroud) 如何在主要浏览器中禁用特定输入和/或完整表单的自动完成功能.
我找到了这个解决方案
<input type="text" name="foo" autocomplete="off" />
Run Code Online (Sandbox Code Playgroud)
但是,这似乎并不适用于所有浏览器.我在firefox中遇到过问题.
编辑:
我的firefox问题已经解决了.这留下了以下内容:我可以在表单上禁用自动完成功能,还是必须为每个输入提供autocomplete ="off"
我正在为我们的客户建立一页一页的结账.此结帐应包含凭据,发货和付款的所有表格.也应该可以编辑先前输入的值.这一切都很好,除了一件事.
我的页面由多个包含:
在每个包含中,我检查相关数据是否在会话中,如果是,我显示不同的视图.这里没什么特别的.
例如:
<?php
if (is_array($_SESSION['credentials'])) {
... show filled in values ...
} else {
... show form ...
}
?>
Run Code Online (Sandbox Code Playgroud)
当值已经设置时,我还会显示一个编辑按钮.我这样做如下:
<div class="left-column">
<h1 class="title-left">Step 1 - Credentials</h1>
<div class="pull-left" style="width: 50%;">
Name: name<br />
Address: Address 11<br />
Postal Code: 12345AA<br />
Country: Country<br />
</div>
<br />
<div style="clear: both;height: 10px;"></div>
<center>
<form method="POST" action="/checkout/credentials/">
<input type="hidden" name="edit" value="credentials">
<button class="sexybutton sexysimple sexybestel">Edit</button>
</form>
</center>
</div>
Run Code Online (Sandbox Code Playgroud)
其次是:
<div class="left-column">
<h1 class="title-left">Step 2 …Run Code Online (Sandbox Code Playgroud) 几个小时以来,我一直在努力做出你能想象到的最简单的事情而且它不起作用.我已经阅读了大量的stackoverflow问题,阅读有关配置文件的完整Symfony文档以及我阅读的每篇文章或其他信息,它变得越来越难以理解.
我创建了自己的Bundle.让我们来称呼它HappyBundle.我把这个Bundle放在我公司的文件夹里.所以我很自然CompanyHappyBundle.
我想专门为这个bundle创建一个配置文件,因为我希望它可以重用.
当我测试我创建了以下内容:
# src/Company/HappyBundle/Resources/config/config.yml
company_happy:
import:
path: /tmp
Run Code Online (Sandbox Code Playgroud)
现在,我想要的是能够在我的控制器中使用此值.我只是不知道如何.它抛出以下错误:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "company_happy" (in /home/user/symfony/src/Company/HappyBundle/Resources/config/config.yml).
Looked for namespace "company_happy", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in /home/user/symfony/src/Company/HappyBundle/Resources/config/config.yml (which is being imported from "/home/user/symfony/app/config/config.yml").
Run Code Online (Sandbox Code Playgroud)
在config.yml中我添加了以下内容:
#app/config/config.yml
imports:
- { resource: "@CompanyHappyBundle/Resources/config/config.yml" }
Run Code Online (Sandbox Code Playgroud)
我也做了一个Configuration类,因为我读到了这个必需的地方.我真的认为这只是一个配置文件的工作.
namespace Company\HappyBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public …Run Code Online (Sandbox Code Playgroud) 我在PHP中使用IMAP函数来处理我的电子邮件并将它们导入数据库.导入后,我将每封电子邮件移动到另一个文件夹以保持分离.
public function moveMail($mailId, $mailBox) {
return imap_mail_move($this->getImapStream(), $mailId, $mailBox, CP_UID) && $this->expungeDeletedMails();
}
Run Code Online (Sandbox Code Playgroud)
移动它们后,我确定电子邮件是否相关.如果不是,我想将其移动到第二个文件夹.但是,移动它后,内部邮件ID被更改,因此我无法再移动电子邮件.
我正在寻找一种方法来获取移动电子邮件的ID,以便我可以再次移动它.
有任何想法吗?