我正在使用Symfony2 Bundle KnpSnappyBundle将html twig模板转换为pdf.
KnpSnappyBundle基于Snappy包装器,使用wkhtmltopdf.
我的模板使用twitter bootstrap 2.3.2 css,如下所示:
<div class="container">
<div class="row">
<div class="span12">
<h4>TITLE</h4>
</div>
</div>
<div class="row">
<div class="span6" id="customers">
<h5>TITLE</h5>
<p>TEXT</p>
<ul class="unstyled">
<li>LIST ITEM</li>
<li>LIST ITEM</li>
<li>LIST ITEM</li>
<li>LIST ITEM</li>
</ul>
</div>
<div class="span6" id="estimate">
<h5>TITLE</h5>
<ul class="unstyled">
<li>LIST ITEM</li>
<li>LIST ITEM</li>
<li>LIST ITEM</li>
<li>LIST ITEM</li>
</ul>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
问题:客户和估计跨度不应该在同一条线上.我不知道发生了什么事.
我正在尝试在奏鸣曲管理包中添加一个动作.我更改了我的Admin类:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
// add custom action links
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'calculate' => array('template' => 'myappMyBundle:Admin:list__action_calculate.html.twig'),
'edit' => array(),
)
))
;
}
Run Code Online (Sandbox Code Playgroud)
和
protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null)
{
if (!$childAdmin && !in_array($action, array('edit'))) {
return;
}
$admin = $this->isChild() ? $this->getParent() : $this;
$id = $admin->getRequest()->get('id');
$menu->addChild('calculate', array('uri' => 'http://google.com?id=' . $id));
}
Run Code Online (Sandbox Code Playgroud)
并在src/myapp/MyBundle/Resources/views/Admin /中放入一个名为list__action_calculate.html.twig的模板:
{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %} …
Run Code Online (Sandbox Code Playgroud) 我想在sonata管理包中自定义编辑页面中表单字段的呈现, 以包含使用字段文本内容的applet.
我知道我必须configureFormFields
在admin类中编辑该函数,但我需要知道3件事:
我想在Snappy和Wkhtmltopdf生成的每个页面的页脚中都有页码,但我没有找到任何关于它的线索.
我可以设置页脚文本(选项'页脚中心'),但如何设置页码?
我不久前写过一个包含脚本的脚本
from lxml import etree
Run Code Online (Sandbox Code Playgroud)
但是,不幸的是它不再起作用了.有疑问我检查安装:
sudo apt-get install python-lxml
sudo pip install lxml
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
Run Code Online (Sandbox Code Playgroud)
我检查了它是否可能是我的python版本:
me@pc:~$ python
Python 2.7.3 (default, Sep 14 2012, 14:11:57)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lxml
Run Code Online (Sandbox Code Playgroud)
我的os是ubuntu 12.04.1 LTS with Python 2.7.3.
一切似乎都很好.我看不出有什么问题.
解决了:
最后导入etree
from xml import …
Run Code Online (Sandbox Code Playgroud) 我有一个NetworkX图.我想知道如何在多个节点之间进行边缘收缩.
例如,如果我想收缩X,Y和Z:
_ node A _
_/ | \_
node X --- node Y --- node Z
Run Code Online (Sandbox Code Playgroud)
会成为
node A
|
node XYZ (or whatever X/Y/Z)
Run Code Online (Sandbox Code Playgroud)
图形创建不是问题.有用.我想通过合并具有相同"含义"的节点来减少图形:我称之为"end lvl"的节点(节点名称长度等于7)并且它们链接在一起.
我在NetworkX中找到了缩合功能,所以我尝试使用它:
# edge contraction for same nodes
# for each node, get the links to other nodes "end lvl"
# if there is such a link, it means that these node are
# the sames
#
# copy graph
I = G
for n,d in G.nodes(data=True):
if n …
Run Code Online (Sandbox Code Playgroud) 我发现Doctrine数组类型使用序列化/反序列化并将数据存储在"简单"字段中,如text,integer.
但我有一个带有postgres数据库的项目,其中一些字段为数组(主要是文本).我想将该数据库与Doctrine一起使用.有办法处理吗?
谢谢
编辑:
ps:我现在知道sql数组可以是一个很好的做法,感谢Craig Ringer.
也许我可以创建自定义类型.是否有人已经做到了?
编辑2:
问题解决了一半:
<?php
namespace mysite\MyBundle\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* My custom postgres text array datatype.
*/
class TEXTARRAY extends Type
{
const TEXTARRAY = 'textarray'; // modify to match your type name
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDoctrineTypeMapping('TEXTARRAY');
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
// This is executed when the value is read from the database. Make your conversions here, optionally using the $platform.
return explode('","', trim($value, …
Run Code Online (Sandbox Code Playgroud) 我有一个大约5000个节点和5000个链接的图表,我可以在Chrome中可视化,这要归功于vivagraph javascript库(webgl比svg更快 - 例如在d3中).
我的工作流程是:
问题是渲染具有良好定位节点的布局需要时间.
我的方法是预先计算networkx中的节点位置.这种方法的真正好处在于它最大限度地减少了客户端在浏览器上的工作.但我无法在网页上取得好成绩.我需要这一步的帮助.
节点位置计算的相关python代码是:
## positionning
try:
# Position nodes using Fruchterman-Reingold force-directed algorithm.
pos=nx.spring_layout(G)
for k,v in pos.iteritems():
# scaling tentative
# from small float like 0.5555 to higher values
# casting to int because precision is not important
pos[k] = [ int(i*1000) for i in v.tolist() ]
except Exception, e:
print "positionning failed"
raise
## setting positions
try:
# set position of …
Run Code Online (Sandbox Code Playgroud) 我在我的Symfony2项目中使用FosUserBundle和SonataUserBundle.
我现在感到困惑.我想为实体用户添加字段,但它不起作用.例如,架构没有更新.
这是我的配置:
AppKernel:
...
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle(),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle('FOSUserBundle')
config.yml:
...
# FOSUserBundle Configuration
fos_user:
db_driver: orm # BDD type
firewall_name: main # firewall name
user_class: Application\Sonata\UserBundle\Entity\User # entity class defined
Run Code Online (Sandbox Code Playgroud)
在app/Application/Sonata/userBundle/Entity /中添加了字段的User实体
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
/**
* This file has been generated by the Sonata EasyExtends bundle ( http://sonata- project.org/easy-extends )
*
* References :
* working with object : http://www.doctrine-project.org/projects/orm/2.0 /docs/reference/working-with-objects/en
*
* @author <yourname> <youremail>
*/
class User extends BaseUser
{
/** …
Run Code Online (Sandbox Code Playgroud) 我想从带有twig的symfony2控制器生成文件文本.
像普通的html模板但使用纯文本,并将文件保存在某处.
可能吗 ?
我是yeoman和grunt的新手,我不知道如何将我在app目录中创建的文件夹复制到dist目录.
该文件夹是/ data/locales/lng/_ ns _.json,有几个lng文件夹和多个ns文件.
我想将整个结构复制到dist目录.
我尝试了复制任务并添加了这个:
{
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'data/**/*.{json}'
]
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
symfony ×4
php ×3
python ×3
symfony-2.1 ×3
graph ×2
networkx ×2
sonata-admin ×2
wkhtmltopdf ×2
arrays ×1
composer-php ×1
css ×1
directory ×1
doctrine ×1
doctrine-orm ×1
edges ×1
file ×1
forms ×1
gruntjs ×1
html ×1
lxml ×1
nodes ×1
packagist ×1
pdf ×1
postgresql ×1
snappy ×1
text ×1
twig ×1
wrapper ×1
yeoman ×1