我有一个以前生成的XML,如下所示:
<newsletter>
<header>
</magazine>
</image>
<strap/>
</header>
<intro>
<date/>
<text/>
</edimg>
</intro>
<shop>
<heading/>
<article/>
<title/>
<img/>
<link/>
<excerpt/>
</shop>
<sidebar>
<cover/>
<cover_link/>
<text/>
<advert>
<link/>
<image/>
</advert>
</sidebar>
</newsletter>
Run Code Online (Sandbox Code Playgroud)
我需要能够在元素<intro>和<shop>元素之间插入一个元素
这个:
$section = $dom->documentElement->appendChild($dom->createElement('section'));
Run Code Online (Sandbox Code Playgroud)
将只在其中创建元素<newsletter>.
我认为这会相当简单,但似乎无法找到解决方案.
谢谢.
我试图将一些Symfony表单组件包含到我的项目中.
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
Run Code Online (Sandbox Code Playgroud)
如果我这样做,我得到:
Fatal error: Class 'Symfony\Component\Form\Form' not found
Run Code Online (Sandbox Code Playgroud)
即使我知道这是Form元素的位置.运用
require 'Symfony\Component\Form\Form.php'
工作,但我需要别名表单元素,以使类工作.
编辑:将ClassLoader复制到项目后尝试此操作仍会带来相同的错误:
require_once __DIR__.'/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => __DIR__.'/Symfony',
));
$loader->register();
Run Code Online (Sandbox Code Playgroud) 我有一个隐藏的领域.在下降事件之后,它需要转换为'textarea'.
这个:
excerpt = $(parent).find('#excerpt').attr('type', 'textarea');
excerpt.val('textarea');
Run Code Online (Sandbox Code Playgroud)
生产
财产不能改变
错误
此方法:将 元素类型从隐藏更改为输入
marker = $('<span />').insertBefore('#myInput');
$('#myInput').detach().attr('type', 'textarea').insertAfter(marker);
marker.remove();
Run Code Online (Sandbox Code Playgroud)
没有使用'textarea',但只适用于'text'.添加:
.val('HERE')
Run Code Online (Sandbox Code Playgroud)
致:
$('#myInput').detach().attr('type', 'textarea').val('HERE').insertAfter(marker);
Run Code Online (Sandbox Code Playgroud)
line确实导致文本框的值发生变化,因此选择器正在工作,并且<span>正在插入和删除元素.
这是一个不可逾越的安全问题吗?或者有办法吗?
Magento 1.3
我正在尝试过滤productCollection中的缺货商品.使用:
->addAttributeToFilter('status',array('neq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED))
Run Code Online (Sandbox Code Playgroud)
我可以按状态过滤,但在此商店中,已启用的产品仍可以有0个数量.
使用:
->addAttributeToFilter('qty', array('gt' => 0))
Run Code Online (Sandbox Code Playgroud)
返回'qty'不是属性错误.
$this->_productCollection = $this->_productCollection->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addAttributeToFilter('status',array('neq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED))
->setPageSize($this->getToolbarBlock()->getLimit());
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢.
我正在尝试从Symfony2返回JSONP.我可以很好地返回常规的JSON响应,但好像JSON响应类忽略了我的回调.
$.ajax({
type: 'GET',
url: url,
async: true,
jsonpCallback: 'callback',
contentType: "application/json",
dataType: 'jsonp',
success: function(data)
{
console.log(data);
},
error: function()
{
console.log('failed');
}
});
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中:
$callback = $request->get('callback');
$response = new JsonResponse($result, 200, array(), $callback);
return $response;
Run Code Online (Sandbox Code Playgroud)
我从中获得的响应始终是常规JSON.没有回调包装.
Json Response类在这里:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/JsonResponse.php
我正在尝试找出在Symfony2中处理自定义错误页面的最佳方法.这包括500和404等.
我可以创建自己的自定义模板(error404.html.twig等)并将它们渲染得很好,问题是,应用程序需要将一些变量传递到基本模板以使页面保持一致.使用内置的异常处理程序会导致所需的变量不可用.
我已成功设置自定义异常事件侦听器,并将其注册为服务:
namespace MyCo\MyBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class MyErrorExceptionListener
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
// We get the exception object from the received event
$exception = $event->getException();
if($exception->getStatusCode() == 404)
{
//$engine = $this->container->get('templating');
//$content = $engine->render('MyBundle:Default:error404.html.twig');
//return $response = new Response($content);
/* Also Tried */
//$templating = $this->container->get('templating');
//return $this->render('MyBundle:Default:index.html.twig');
$response = new Response($templating->render('MyBundle:Exception:error404.html.twig', array(
'exception' => $exception
)));
$event->setResponse($response);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为:$ container不可用,这意味着我无法呈现我的自定义页面.
真的有两个问题,这是处理自定义错误页面的正确方法,还是应该将响应传递给控制器?如果是这样,最好的方法是什么?
如果这是正确的,我如何在我的监听器中提供模板引擎?
我有一个XML feed,我正在使用XSL进行转换.XML中每个帖子的日期都采用以下格式:
2011-03-09T10:44:27Z
我希望能够将其转换为"50分钟前"或"3天前"格式,这是否可以仅使用XSL或PHP是"唯一"选项?
有没有办法使用FQL从页面(而不是从用户页面,而不是业务页面)获取状态更新,"页面"表的文档不包含任何内容?
所以我的查询理论上是:
SELECT status FROM page WHERE page_id = MYPAGEID
Run Code Online (Sandbox Code Playgroud)
虽然这显然不起作用,并且:
SELECT message FROM status WHERE uid = MYPAGEID
Run Code Online (Sandbox Code Playgroud)
只返回NULL.
该页面是公共的,并且所有安全权限都已关闭.
有任何想法吗?我看不出为什么Facebook不允许这样做的原因?
我用过
https://graph.facebook.com/MYPAGEID/feed
Run Code Online (Sandbox Code Playgroud)
但理想情况下,我想返回XML以将其集成到Feed中.
谢谢.
我有一个结构为的 XML 文件:
<root>
<featured>
<title></title>
<tweet></tweet>
<img></img>
</featured>
</root>
Run Code Online (Sandbox Code Playgroud)
元素是动态添加的,用户需要选择在某些情况下删除元素,
我尝试了一些代码变体,包括:
$featureddel = $xpath->query('//featured');
while ( $featureddel->hasChildNodes()){
$featureddel->removeChild($featureddel->childNodes->item(0));
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误:
PHP Fatal error: Call to undefined method DOMNodeList::hasChildNodes()
Run Code Online (Sandbox Code Playgroud)
我也试过:
$featureddel= $dom->getElementsByTagName('featured');
$featureddel->parentNode->removeChild($featureddel);
Run Code Online (Sandbox Code Playgroud)
返回:
PHP Fatal error: Call to a member function removeChild() on a non-object
Run Code Online (Sandbox Code Playgroud) 我需要一个正则表达式从Twitter名称中删除#.
试过这个:
$name = '#mytwitter';
$str = preg_replace('/\#/', ' ', $name);
Run Code Online (Sandbox Code Playgroud)
当然这是一个简单的解决方案,但谷歌没有帮助.谢谢!
我试图将一个变量放入查询中的字段名称,所以我有一个架构:
id amazon - tesco - asda - happyshopper -
1 £5 - NULL - NULL - £4.99
2 NULL - £2.99 - NULL - NULL
Run Code Online (Sandbox Code Playgroud)
然后
$store = 'amazon';
$qb = $em->createQueryBuilder();
$products = $qb->select('p')->from('MyBundle:Product', 'p')
->where('p.:store IS NOT NULL')
->setParameter('store', $store)
->add('orderBy', 'p.onSale DESC')
->setMaxResults(40)
->getQuery()
->getResult();
Run Code Online (Sandbox Code Playgroud)
将返回第1行.
我做了什么:
->where('p.:store IS NOT NULL')
->setParameter('store', $store)
Run Code Online (Sandbox Code Playgroud)
是不正确的,它是错误的.
->where(':store IS NOT NULL')
->setParameter('store', $store)
Run Code Online (Sandbox Code Playgroud)
不会出错,但不会应用商店过滤器.
我有一个对象数组:
[0] ProductObject
Title
Image
Link
[1] ProductObject
Title
Image
Link
Run Code Online (Sandbox Code Playgroud)
等等
我可以将这些对象精确地传递给我的形式:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add(
'products',
'choice',
array(
'choices' => $productsArray,
'multiple' => false,
'required' => false
)
);
}
Run Code Online (Sandbox Code Playgroud)
然后在模板中:
{{ form_label(form.products, 'products') }}
{{ form_errors(form.products) }}
{{ form_widget(form.products) }}
{{ form_rest(form) }}
Run Code Online (Sandbox Code Playgroud)
现在,正如预期的那样,表单呈现出来:
<optgroup label="0">
<option value="id">174</option>
<option value="title">A Bag Of Frogs</option>
<option value="image">Image</option>
<option value="link">http://www.myshoppe.com</option>
</optgroup>
Run Code Online (Sandbox Code Playgroud)
我只希望在下拉列表中有标题,但我希望保持图像和链接可用,因为我想使用javascript在用户选择产品后立即用图像标题和链接填充另一个div.
所以,问题是"如何在Twig中隐藏对象属性?"
要么
这是荒唐的吗?
:)
嗨,我有一个多维关联数组:
$array= array(
'Book1' => array('http://www.google.com', '45' ),
'Book2' => array('http://www.yahoo.com', '46', )
)
Run Code Online (Sandbox Code Playgroud)
我需要能够在'BookX'上搜索$ array,然后返回'BookX'的内容.
我试过了:
function array_searcher($needles, $array)
{
foreach ($needles as $needle) {
foreach ($array as $key )
{
if ($key == $needle)
{
echo $key;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
随着搜索
$needles = array('Book1' , 'Book2' );
Run Code Online (Sandbox Code Playgroud)
但这并不能归还任何东西