当我需要显示一个汽车和它的品牌之间的OneToMany关系时,我有一个表格.
当我现在点击下拉列表时,我只能看到汽车名称.因为它是从汽车实体自动创建的.
我想在我的下拉列表中看到的是NameOfTheCar - NameOfTheBrand.适合各种选择
我的CarType有一个类似于:
$builder->add('cars', 'choice', array(
'choices' => array(
'Test' => 'Example',
),
'required' => true,
));
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?
编辑:我跟随雨果的建议.
现在我知道了
$builder->add('lake', 'entity', array(
'class' => 'Pondip\KeepnetBundle\Entity\CatchReport',
'required' => true,
));
Run Code Online (Sandbox Code Playgroud)
我的CatchReport的__toString是
public function __toString()
{
return $this->car .' - '. $this->car->getBrand();
}
Run Code Online (Sandbox Code Playgroud)
当湖是
/**
* @var integer
*
* @ORM\ManyToOne(targetEntity="Pondip\CarBundle\Entity\Car")
* @ORM\JoinColumn(name="car_id", referencedColumnName="id")
* @Assert\NotBlank()
*/
private $car;
Run Code Online (Sandbox Code Playgroud)
在我的品牌实体中,我有:
/**
* @var integer
* @Assert\Type(type="Pondip\CarBundle\Entity\Brand")
*
* @ORM\ManyToOne(targetEntity="Pondip\CarBundle\Entity\Brand")
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
*/
private $brand;
Run Code Online (Sandbox Code Playgroud)
现在我的toString()函数出错了.我做错了什么 ? …
我试图设置一个左边的meny,其中li元素伸展到屏幕的整个高度,无论屏幕的大小.
我不能让li元素用css3 flex属性填充整个屏幕高度.我一直在寻找一份好的文档:
http://css-tricks.com/snippets/css/a-guide-to-flexbox/
我正在使用一系列ul元素.不知道这是不是造成了这个问题..
这就是我想要做的:
#left-drawer-menu {
width: 100%;
list-style-type: none;
margin: 0px;
padding: 0px;
display: -webkit-flex;
-webkit-flex-direction: column;
display: flex;
flex-direction: column;
}
#left-drawer-menu li{
background-color: white;
text-align: center;
min-height: 100px;
height: 20%;
}
<ul id="left-drawer-menu">
<li data-icon="contacts"><span class="km-icon km-mostrecent"></span>Available 1</li>
<li data-icon="globe"><span class="km-icon km-mostviewed"></span>Available 2</li>
<li data-icon="camera"><span class="km-icon km-organize"></span>Available 3</li>
<li data-icon="organize"><span class="km-icon km-featured"></span>Available 4</li>
<li data-icon="settings"><a href="#profile"><span class="km-icon km-action"></span>Available 5</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我一直在关注如何配置Web服务器的Symfony 4文档。
https://symfony.com/doc/current/setup/web_server_configuration.html
我的apache 2.4配置中的.conf文件与他们的文档中所述完全相同。我在这里复制了一部分:
<Directory /var/www/project/public>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
Run Code Online (Sandbox Code Playgroud)
转到我的平台,一切正常,但是一旦我转到任何页面,它就会显示404错误。如果我在网址中添加index.php,则效果很好。您能帮我弄清楚发生了什么吗?
例如:当我在http://myplatform.com/上时
我可以在此页面上保存电子邮件地址。如果我访问http://myplatform.com/index.php/saveEmail,它可以工作,但是从我的页面上,我的链接将我重定向到http://myplatform.com/saveEmail,但它不起作用。
如果我转到http://myplatform.com/index.php,则一切正常。
如何从URL中删除index.php?
谢谢!
我一直在尝试设置一个表单Symfony 2。
因此,我按照教程创建了一个特殊的类,用于创建表单并在控制器外部处理验证过程(如文档中所示)
但现在我需要自动填写一个字段,我听说我必须在创建表单(针对我的产品)的 ProductType.php 中执行此操作。
但我不知道该怎么做,这是我在 ProductType.php 中的 buildForm 函数:
class QuotesType extends AbstractType
{
private $id;
public function __construct($id){
$this->product_id = $id;
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('user_name', 'text')
->add('user_lastname', 'text')
->add('user_email', 'email')
->add('user_comments', 'textarea')
->add('user_product_id', 'hidden', array(
'data' => $this->product_id,
));
;
}
Run Code Online (Sandbox Code Playgroud)
显然它不起作用,因为我收到一个 SQL 错误,说我的字段为空。
如何为 user_product_id 设置默认值?我应该直接对对象进行操作吗?
编辑:
这是我的实体的代码的一部分:
namespace QN\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* QN\MainBundle\Entity\Quotes
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="QN\MainBundle\Entity\QuotesRepository") …Run Code Online (Sandbox Code Playgroud) 我在尝试调整图像大小然后创建一个拇指时遇到了麻烦.
这两个功能都是单独工作的,但在尝试同时调用它们时,只有第一个呼叫有效.没有创建Thumb,为什么?
这是我的控制器:
if($this->upload->do_upload()){
// Si oui, tout va bien
//Update DB
$pictureData = $this->upload->data();
if($pictureData['file_name']!=''){
//On resize l'immage
//On charge la librarie
$this->load->library('thumbs');
$this->thumbs->resize($pictureData['full_path'], 300, 600);
$News['image']=$pictureData['file_name'];
//On crée un Thumbnail:
// on envoi le full path
if($this->thumbs->create($pictureData['full_path']))
// on stock le path recu
$News['thumb'] = $pictureData['raw_name'].'_thumb'.$pictureData['file_ext'];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我为这两个函数创建的库:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Thumbs
{
function __construct()
{
$CI =& get_instance();
$this->load->library('image_lib');
}
public function create($picPath) {
$CI =& get_instance();
$config['image_library'] = 'gd2'; …Run Code Online (Sandbox Code Playgroud) 我在MAMP上安装了PECL for PHP.不幸的是,它使用的是php 5.3.6,它与最新版本的PHP(今天是5.4.10)不同.在查看phpinfo时,我看到它没有加载我想要的php.ini文件(5.3.6),它正在加载最新的文件(这是正常的)
如何告诉MAMP使用哪个版本的PHP?
谢谢
我希望在 symfony4 中实现 KnpPaginatorBundle。
我的问题是,在他们的文档(适用于 S3)中,他们建议使用以下参数 i config.yml。
knp_paginator:
page_range: 5 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements …Run Code Online (Sandbox Code Playgroud) 我有一系列这样的数字
$arr = range(01,10);
Run Code Online (Sandbox Code Playgroud)
但我希望输出
Array ( [0] => 01 [1] => 02 [2] => 03 ... [9] => 10)
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
我有一个表单,我希望用户选择2种不同的结帐方式:
假设用户输入他的信息,例如他的地址,姓名和信用信息.使用Paypal Pro,最后,我希望他能够选择是否要通过paypal或通过直接付款结账......这将导致第二种形式.
顺便说一下,使用CodeIgnieter,当跟随另一个表单时,我得到了第二个表单总是运行的验证过程,我的意思是当我从第一个表单到第二个表单时,在第二个表单中我会看到我的即使用户尚未尝试提交,也会显示每个字段的错误消息.有没有办法避免这个错误?
谢谢 !
我的代码中有类似的东西:
<?php foreach($clients as $client): ?>
<tr class="tableContent">
<td onclick="location.href='<?php echo site_url('clients/edit/'.$client->id ) ?>'"><?php echo $client->id ?></td>
<td>
<a class='Right btn btn-danger' onClick="ConfirmMessage('client', <?php $client->id ?>,'clients')">
<i class="icon-remove-sign icon-white"></i>
</a>
</td>
</tr>
<?php endforeach ?>
Run Code Online (Sandbox Code Playgroud)
这实际上就是观点.因此,当用户点击删除按钮(使用btn-danger类时),我希望他通过javascript确认框消息确认他的选择.您可以在标题中找到该脚本
function ConfirmMessage(type, id, types) {
if (confirm("Are you sure you want to delete this ",type," ?")) { // Clic sur OK
document.location.href='<?php echo site_url(); ?>',types,'/delete/',id;
}
}
Run Code Online (Sandbox Code Playgroud)
所以这是我的问题:
我想将$ type替换为我将传递给函数的参数(如客户端,文章,帖子......).我也想获得$client->id参数.我在javascript中很糟糕,正如你已经猜到的那样,它显然根本不起作用.
php ×5
symfony ×4
forms ×3
codeigniter ×2
symfony4 ×2
arrays ×1
confirm ×1
css ×1
css3 ×1
flexbox ×1
html ×1
html-lists ×1
javascript ×1
knppaginator ×1
mamp ×1
one-to-many ×1
paypal ×1
pecl ×1
range ×1
routing ×1
url ×1
validation ×1
version ×1