我的应用程序的服务需要访问一个名为的$_SERVER变量(由apache提供):$_SERVER['GEOIP_COUNTRY_CODE'];
有什么好方法可以达到这个目的?
我目前的猜测是注入RequestStack但另一方面我不想将完整的RequestStack耦合到这个服务.
还有其他方法可以实现这一目标吗?
PS请不要回复我的链接,如https://github.com/aferrandini/Maxmind-GeoIp等.
我的功能有些问题.
我做一个SQL查询来获取一个列表,该列表包含一些只有一个键/值元素的字典.这是我输出的一个示例:
myDictList = [{'id': 55, 'sigla': 'SNG'}, {'id': 62, 'sigla': 'TRP'},
{'id': 71, 'sigla': 'PCNIM'}, {'id': 72, 'sigla': 'pc2ni'},
{'id': 73, 'sigla': 'ccas'}, {'id': 74, 'sigla': 'ased1'},
{'id': 75, 'sigla': '131s'}, {'id': 76, 'sigla': 'r888'},
{'id': 56, 'sigla': 'DBL'}]
Run Code Online (Sandbox Code Playgroud)
这id是唯一的(对于SQL约束).
我id以这种方式建立了一个列表
r_id_list = list(rid['id'] for rid in roomList)
Run Code Online (Sandbox Code Playgroud)
现在,我会建立一个字典.像那样myDictList:
{55:'SNG',62:'TRP',71:'PCNIM'.... and so on}
Run Code Online (Sandbox Code Playgroud)
更重要的是,我想避免像这样的部分代码:
finalDict = {}
for element in myDictList:
finalDict.update({element['id']:element['sigla']})
Run Code Online (Sandbox Code Playgroud)
我想这样做是出于某些原因:
sigla的值r_id_list元素一些建议的紧凑代码不包括for循环内的for …
我有这种情况
EntityA涉及EntityB到一个一对多的方式.我已经创建了一个表单EntityB,我想选择(带有复选框)一些EntityA元素.
我怎样才能做到这一点?
UPDATE
public function viewAction()
{
$id_struttura = 9;
$channel_rates = $this->getDoctrine()->getRepository('SestanteChannelManagerBundle:StrutturaCanaleTariffa')->findByStruttura($id_struttura);
$list = array();
foreach ($channel_rates as $channel_rate) {
$list[$channel_rate->getId()] = $channel_rate->getNomeCameraTariffa();
}
$view = new View();
$view->addChannelRate($channel_rates);
$form = $this->createForm(new ViewType(), $view);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$dateRange = new DateRange($date_from, $date_to);
$channelDisp = $this->get('channel_dispatcher');
$inventories = $channelDisp->queryAvailabilityRates($dateRange, $channelRateList);
return $this->render('SestanteCDTestBundle:Main:view_result.html.twig', array('inventories' => $inventories));
}
}
return $this->render('SestanteCDTestBundle:Main:view.html.twig', array('form' => …Run Code Online (Sandbox Code Playgroud) 对于我正在编写的模块,我需要在调用链接并传递一些数据之后为某个用户检索购物车(不需要注册).
我的想法是收回以前通过的ID,可以帮助我识别某个购物车.
我最大的问题是我已经搜索了很多代码购物车创建到prestashop.最后我发现了一些东西
/* Cart already exists */
if ((int)$this->context->cookie->id_cart)
{
$cart = new Cart($this->context->cookie->id_cart);
if ($cart->OrderExists())
{
unset($this->context->cookie->id_cart, $cart, $this->context->cookie->checkedTOS);
$this->context->cookie->check_cgv = false;
}
/* Delete product of cart, if user can't make an order from his country */
elseif (intval(Configuration::get('PS_GEOLOCATION_ENABLED')) &&
!in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) &&
$cart->nbProducts() && intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 &&
!FrontController::isInWhitelistForGeolocation() &&
!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
unset($this->context->cookie->id_cart, $cart);
// update cart values
elseif ($this->context->cookie->id_customer != $cart->id_customer || $this->context->cookie->id_lang != $cart->id_lang || $currency->id != $cart->id_currency)
{
if ($this->context->cookie->id_customer)
$cart->id_customer …Run Code Online (Sandbox Code Playgroud) 我在内存分配/释放方面遇到了一些麻烦.
在"64位机器"上,我运行了一些没有错误的c代码.如果我在32位机器上运行相同的代码(重新编译后,obv.)我有一些分段故障的麻烦.
这是我的glib-c版本:
包:libc6
新增:是状态:已安装自动安装:无版本:2.13-20ubuntu5优先级:必需部分:libs维护者:Ubuntu开发人员未压缩大小:10,7 M取决于:libc-bin(= 2.13-20ubuntu5),libgcc1,tzdata建议:glibc-doc,debconf | debconf-2.0,locales冲突:belocs-locales-bin,belocs-locales-bin,libc6-amd64,libc6-amd64,prelink(<0.0.20090925),prelink(<0.0.20090925),tzdata(<2007k-1) ,tzdata(<2007k-1),tzdata-etch,tzdata-etch中断:nscd(<2.13),nscd(<2.13),libc6(!= 2.13-20ubuntu5)替换:belocs-locales-bin,belocs-locales- bin,libc6-amd64,libc6-amd64,libc6(<2.13-20ubuntu5)提供:glibc-2.13-1描述:libreria C GNU嵌入式:librerie condivise
在32位机器上,版本是:
2.06-01
更重要的是,这里有一些令我疯狂的代码片段:
void estrai_libro (FILE* fileDescriptor, Libro* libroLetto) {
char* ptr_buf;
size_t n;
size_t lung;
ssize_t nread;
/* ---- questo blocco di istruzioni verrà utilizzato per tutti
i campi della struttura Libro passata in input */
/* inizializzo ptr_buf e n rispettivamente a NULL e a 0 in moda da
da sfruttare al meglio la getline(...)*/
ptr_buf = NULL;
n = 0;
/* copio …Run Code Online (Sandbox Code Playgroud) 我想看一下源代码file_get_contents.
我已经谷歌搜索了几个小时,但无法找到它或它在PHP下载的位置.
我下载了php-5.4.15.
有谁知道我在哪里可以找到这个?
我创建了一个实体Testme并使用它生成了 crud 文件bin/console make:crud并尝试向表单添加验证规则,但它不起作用:
我的实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\TestmeRepository")
*/
class Testme
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Assert\NotBlank()
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
....
Run Code Online (Sandbox Code Playgroud)
表格:
<?php
namespace App\Form;
use App\Entity\Testme;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class TestmeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder …Run Code Online (Sandbox Code Playgroud) 我有一个表HelloWorld,列有英文,西班牙,法国,中国
我不知道哪个更适合向此表添加数据.
Insert into HelloWorld values ("Hello", "hola", "bonjour", "nihao");
Insert into HelloWorld (english, spain, france, china) values ("hello", "hola", "bonjour","nihao");
你能告诉我两个以上选项哪个更好.我感谢任何答案和解释.