小编Eln*_*mov的帖子

Symfony2捆绑:我使用它们吗?

我有一个在Symfony2中开发的应用程序.现在它的结构如下:

  • FrontBundle - 包括与应用程序视图和UI相关的所有内容.
  • PersistanceBundle - 包括与应用程序的持久层相关的所有内容.
  • DomainBundle - 包括与应用程序实体和服务相关的所有内容.

这个结构好吗?或者像论坛功能一样使用捆绑包 - ForumBundle - 包括与论坛相关的每个层(控制器,服务,域逻辑持久性).

php symfony

11
推荐指数
2
解决办法
4623
查看次数

Symfony2表单和多态集合

我正在玩Symfony2和Im abit不确定Symfony2如何在View组件中处理Polymorphic集合.看来我可以创建一个包含AbstractChildren集合的实体,但不知道如何在Form Type类中使用它.

例如,我有以下实体关系.

/**
 * @ORM\Entity
 */
class Order
{
    /**
     * @ORM\OneToMany(targetEntity="AbstractOrderItem", mappedBy="order", cascade={"all"}, orphanRemoval=true)
     * 
     * @var AbstractOrderItem $items;
     */
    $orderItems;  
    ...
}


/**
 * Base class for order items to be added to an Order
 *
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({
 *     "ProductOrderItem" = "ProductOrderItem",
 *     "SubscriptionOrderItem " = "SubscriptionOrderItem "
 * })
 */
class AbstractOrderItem
{
    $id;
    ...
}

/**
 * @ORM\Entity
 */
class ProductOrderItem  extends AbstractOrderItem
{
    $productName;
}

/** …
Run Code Online (Sandbox Code Playgroud)

polymorphism doctrine symfony

11
推荐指数
1
解决办法
5441
查看次数

Spring/Junit/JPA的依赖注入

我正在尝试使用Spring 2.5.6和JUnit 4.8.1为我的JPA DAO类创建JUnit测试.

我的测试用例如下:


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:config/jpaDaoTestsConfig.xml"} )
public class MenuItem_Junit4_JPATest extends BaseJPATestCase {

    private ApplicationContext context;
    private InputStream dataInputStream;
    private IDataSet dataSet;

    @Resource
    private IMenuItemDao menuItemDao;

    @Test
    public void testFindAll() throws Exception {
        assertEquals(272, menuItemDao.findAll().size());
    }

    ... Other test methods ommitted for brevity ...
}
Run Code Online (Sandbox Code Playgroud)

我在jpaDaoTestsConfig.xml中有以下内容:


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx.xsd">

  <!-- uses the persistence unit defined in the META-INF/persistence.xml JPA configuration file -->
  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="CONOPS_PU" /> 
  </bean> …
Run Code Online (Sandbox Code Playgroud)

junit spring jpa

10
推荐指数
1
解决办法
3万
查看次数

针对不同环境的不同security.yml文件

我无法找到一种方法来security.yml包含根据Symfony2环境包含的不同文件.例如,我想为我的验收测试提供一个内存用户提供程序,因为我不需要在这里测试我的实体和内容,我只想对我的视图进行验收测试.

但是,事实证明,这并不容易.我security.yml从我的包中删除config.yml,重命名为security_prod.yml并创建了一个security_test.yml具有in_memory用户提供程序的包.然后,我已经包括了security_prod.ymlsecurity_test.yml我的生产和测试分别CONFIGS.

但它似乎根本不起作用:

$ SYMFONY_ENV=test app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]                                                           
  You are not allowed to define new elements for path "security.providers". Please define all elements for this path in one config file.  

$ SYMFONY_ENV=prod app/console cache:clear                                                      

  [Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException]                                                                         
  Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one   
  configuration section.                                                                                                                              
Run Code Online (Sandbox Code Playgroud)

在我看来,security.yml文件名是硬编码的(这对于Symfony来说太奇怪了),但事实并非如此.

所以问题是:如何security.yml …

php symfony

10
推荐指数
1
解决办法
3936
查看次数

Symfony 2中的2级实体文件夹

我在Symfony2包中有一个两级实体文件夹:

CommonBundle/Entity/EntityFolder1/EntityA.php
CommonBundle/Entity/EntityFolder2
CommonBundle/Entity/EntityFolder3
CommonBundle/Entity/EntityFolder4
Run Code Online (Sandbox Code Playgroud)

当我尝试获取其中一个文件夹中的实体的存储库时:

$product = $this->getDoctrine()->getRepository('CommonBundle:EntityA')->find(1); 
Run Code Online (Sandbox Code Playgroud)

Symfony不承认这一点CommonBundle:EntityA.

我也尝试过CommonBundle:EntityFolder1:EntityA.

警告:class_parents():类CommonBundle\Entity\EntityA不存在且无法加载

symfony doctrine-orm

10
推荐指数
1
解决办法
3249
查看次数

在SonataAdminBundle中添加操作

我正在尝试在奏鸣曲管理包中添加一个动作.我更改了我的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)

symfony symfony-2.1 sonata-admin

10
推荐指数
1
解决办法
9400
查看次数

升级Cassandra而不会丢失当前数据

我当前版本的Cassandra是2.2.4,我想将其升级到3.0.10而不丢失任何数据.这怎么可能?

我的群集由3个节点组成,复制因子为2.此更新是否会影响我的群集体系结构?

cassandra

10
推荐指数
2
解决办法
7943
查看次数

Xlib如何(删除窗口装饰)工作?

以下代码如何删除窗口边框?

//note the struct is declared elsewhere, is here just for clarity.
//code is from [http://tonyobryan.com/index.php?article=9][1]
typedef struct Hints
{
    unsigned long   flags;
    unsigned long   functions;
    unsigned long   decorations;
    long            inputMode;
    unsigned long   status;
} Hints;

//code to remove decoration
Hints hints;
Atom property;
hints.flags = 2;
hints.decorations = 0;
property = XInternAtom(display, "_MOTIF_WM_HINTS", true);
XChangeProperty(display,window,property,property,32,PropModeReplace,(unsigned char *)&hints,5);
XMapWindow(display, window);
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经收集到Atom是一种类似于Window和Display的标识符,但我无法弄清楚Hints结构或"_MOTIF_WM_HINTS"的来源.谁能为我解释所有这些代码?在此先感谢,ell.

c++ linux window-managers xlib

9
推荐指数
1
解决办法
6541
查看次数

Spring Java config:导入属性文件

如何在使用Java配置配置Spring时导入属性文件并访问属性.

我想用java做所有事情.有办法吗?

我试过用@ImportResource("classpath:config.properties")但没用.

spring

9
推荐指数
1
解决办法
1万
查看次数

需要spring security java配置示例,仅显示基本身份验证

我当前的java安全配置如下所示:

@Configuration
@EnableWebSecurity
public class RootConfig extends WebSecurityConfigurerAdapter {

@Override
protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception
{
auth.inMemoryAuthentication()
    .withUser("tester").password("passwd").roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
     http
     .authorizeUrls()
         .anyRequest().authenticated()
         .and()
     .httpBasic();       
  }
}
Run Code Online (Sandbox Code Playgroud)

当我使用浏览器执行GET请求时,我将收到错误403.我希望得到一个浏览器弹出窗口,询问我的用户名/密码.可能是什么问题?

spring-security

9
推荐指数
1
解决办法
7576
查看次数