小编Adr*_*n G的帖子

多个spl_autoload_register问题

我正在开发自定义框架.当我试图动态调用我的类时,我遇到了一个问题.

这是我的文件的视觉效果:

在此输入图像描述

所以我决定为每个文件夹(libs,controllers和modeles)创建一个不同的函数:

function autoloadLibs($class) {
    //require the general classes
    require 'libs/' . $class . '.php';
}

function autoloadModels($class) {
    //require the models classes
    require 'models/' . $class . '.php';
}

function autoloadControllers($class) {
    //require the controllers classes
    require 'controllers/' . $class . '.php';
}

spl_autoload_register ('autoloadLibs');
spl_autoload_register ('autoloadControllers');  
spl_autoload_register ('autoloadModels');
Run Code Online (Sandbox Code Playgroud)

不过我有这样的消息:警告:require(libs/admin.php):无法打开流,cours它不是好文件夹.但我不知道如何解决这个问题.有没有一种优化我的类调用的好方法?

php class spl-autoload-register

8
推荐指数
3
解决办法
9455
查看次数

以多对多关系防止数据库中的重复

我正在一家餐馆网站的后台工作.当我添加一道菜时,我可以通过两种方式添加成分.

在我的表单模板中,我手动添加了一个文本输入字段.我在这个字段上应用了jQuery UI的自动完成方法,它允许:

  • 选择现有成分(之前添加)
  • 添加新成分

但是,当我提交表格时,每个成分都会插入数据库中(您将告诉我的正常行为).对于不存在的成分,它是好的,但我不想再插入已插入的成分.

然后我想到了Doctrine事件,比如prePersist().但我不知道如何继续.我想知道你是否知道如何做到这一点.

这是buildForm我的方法DishType:

<?php 

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
    ->add('category', 'entity', array('class' => 'PrototypeAdminBundle:DishCategory',
                                      'property' => 'name',
                                      'multiple' => false ))
    ->add('title', 'text')
    ->add('description', 'textarea')
    ->add('price', 'text')
    ->add('ingredients', 'collection', array('type'        => new IngredientType(),
                                             'allow_add'    => true,
                                             'allow_delete' => true,
                                            ))

    ->add('image', new ImageType(), array( 'label' => false ) );
}
Run Code Online (Sandbox Code Playgroud)

以及我处理表单的控制器中的方法:

<?php
public function addDishAction()
{

    $dish = new Dish(); …
Run Code Online (Sandbox Code Playgroud)

many-to-many duplicates symfony

7
推荐指数
1
解决办法
3033
查看次数

Symfony2 - 注意:由于自定义查询,未定义的偏移量为0

我有这个错误:

"注意:未定义的偏移量:0:C:\ wamp\www\Videotheque\vendor\doctrine\lib\Doctrine\ORM\QueryBuilder.php第240行"

我在线创建视频集.有两个实体:电影和流派.在我的GenRerepository方法中,我尝试将函数findAll()重新定义为与类型相关的电影数量.

这是功能:

public function myFindAll()
{
    $genres = $this->_em->createQueryBuilder('g')
                        // leftJoin because I need all the genre
                        ->leftJoin('g.films', 'f')
                        ->addSelect('COUNT(f)')
                        ->groupBy('g')
                        ->getQuery()
                        ->getArrayResult();
    // $genres contains all the genres and the associated movies
    return ($genres);
}
Run Code Online (Sandbox Code Playgroud)

php entity-relationship doctrine-orm

4
推荐指数
2
解决办法
6654
查看次数

如何在React Router v4路由之间共享应用程序状态

我想知道我必须采用哪种解决方案来解决以下问题:

我不使用任何状态管理库。我“只使用” React。

全局应用程序状态存储在组件中<MyFoodApp/>。它包含一组餐厅对象。

该组件RestaurantPage用于显示餐厅的详细信息,并允许创建新的评论

在这一点上,我陷入了困境,因为我需要更新 restaurant以的状态存储的特定对象<MyFoodApp />才能添加此提交的评论

我曾经通过作为道具传递给子组件的函数来更新状态,但是在这种情况下我不能这样做,因为MyFoodApp它不是的父项RestaurantPage

我是否必须设置Redux以解决此问题,或者有任何解决方法?

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Link, Route, Switch } from 'react-router-dom';

import EasyFoodApp from './js/components/EasyFoodApp';
import RestaurantPage from './js/components/RestaurantPage';
import NotFound from './js/components/NotFound';

class Root extends React.Component {
    render() {
        return (
            <Router>
                <div className="router">
                    <Switch>
                        <Route exact path="/" component={MyFoodApp} …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-router-v4

2
推荐指数
1
解决办法
2701
查看次数