i am new in symfony,its has been two days i have stacked on a problems making drop downs using symfony froms relations based on schema.yml
schema.yml is
FieldsCategory:
tableName: fld_category
columns:
id:
name: id as FieldsId
type: integer(10)
primary: true
autoincrement: true
category_name:
name: category_name as CategoryName
type: string
default: ''
notnull: true
relations:
FieldsCategory:
class: FieldsCategory
foreignAlias: Fields
local: id
foreign: fields_category_id
Fields:
tableName: fld_fields
columns:
id:
name: id as FieldsId
type: integer(10)
primary: true
autoincrement: true
fields_name:
name: fields_name as FieldsName
type: string
default: ''
notnull: true
fields_desc:
name: fields_desc as FieldsDescription
type: string
default: ''
notnull: true
amount:
name: amount as TotalAmount
type: integer
notnull: true
fields_type_id:
name: fields_type_id as FieldsTypeId
type: integer
fields_category_id:
name: fields_category_id as FieldsCategoryId
type: integer
and my forms is
$this->setWidgets(array(
'FieldsId' => new sfWidgetFormInputHidden(),
'fields_type_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Fields'), 'add_empty' => false)),
'FieldsName' => new sfWidgetFormTextarea(),
));
$this->setValidators(array(
'FieldsId' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('FieldsId')), 'empty_value' => $this->getObject()->get('FieldsId'), 'required' => false)),
'fields_type_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Fields'), 'required' => false)),
'FieldsName' => new sfValidatorString(array('required' => false)),
));
its given me this error
i have tried all possible ways but i couldnt solve this problems/
and help will be approciated in advance
Related
i have entity languages with format
id; name
en; English
pl; Polish
etc...
And I have some Entity translations, that in one column has an associative array:
{pl: "Some txt in PL", en: "Some txt in EN",...}
Everything is almost perfect, but i don't know how to create an form for editing such a thing :D I tried almost everything.
Translation.orm.yml:
...
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
unique: true
value:
type: array
...
For new Entity you must prepare your array in Controller ( before creating form). Something like that:
$value = array('en' => 'here en', 'pl' => 'here pl');
$translation->setValue($value);
$form = $this->createForm(new TranslationType()...
In Your FormType:
$builder->add('value', 'collection', array(
'type' => 'text',
'options' => array(
'required' => true,
),
)
);
That's all.
If you have {{ form_rest(form) }} in your twig, you'll see two additional fields for translations in your form and it will be work.
Additional information about collection field type is here
I have this menu:
items:[
{
xtype: 'form',
id: 'searchPanel',
title: 'Search',
collapsible: true,
bodyPadding: 10,
height: 210,
buttonAlign: 'left',
defaults: {
width: 400,
labelWidth: 120,
allowBlank: true,
enableKeyEvents: true
},
layout: {
type: 'table',
columns: 2
},
items: [
{
xtype: 'textfield',
name: 'txtFltrSiteName',
fieldLabel: 'Site name or alias',
id: 'txtFltrSiteName'
},
{
xtype: 'textfield',
name: 'txtDiskCost',
fieldLabel: 'Disk cost',
id: 'txtDiskCost',
style: 'margin-left: 100px;'
},
{
xtype: 'textfield',
name: 'txtFltrProjectName',
fieldLabel: 'Project name',
id: 'txtFltrProjectName'
},
// many other fields
And chackboxes and text fields have diffirent width, so it looks ugly.
So the queston is:
How to make empty <td> in this form?
For examle I want 6-2 items:
----------
| 1 | 1 |
| 2 | 2 |
| 3 | |
| 4 | |
|..etc...|
----------
Just make hidden input.
like this:
{
xtype: 'hidden',
name: 'hidden1',
id: 'hidden1'
},
This will make <td> column, but it'll be empty coz it'll be hidden input in it.
Here's a better one:
{
xtype : 'label',
text : '',
labelSeparator: ''
}
I have a weird problem.
Here's my yaml:
Request:
actAs: { Timestampable: ~ }
columns:
id: { type: integer(4), primary: true, autoincrement: true, notnull: true }
When i perform a symfony doctrine:build --all --no-confirmation inside my BaseRequest.class.php there's an error during the declaration of my id field:
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'primary' => true,
'autoincrement' => true,
'length' => 4,
));
As you can see it should be auto_increment but instead it's autoincrement so i have to manually change this after each build.
Is there any way to fix this ?
not exactly answer to your question, but you don't need to specify id column for your entities, doctrine does that automatically
Doctrine turns my column names into all lower case to improve compatibility. How do I prevent this from happening?
users:
actAs: [Timestampable]
columns:
userId:
type: integer
length: 4
primary: true
autoincrement: true
or
$this->hasColumn('userId', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'primary' => true,
'autoincrement' => true,
));
then becomes
userid
This is a problem because I have lots of existing code and data that uses the camelCase convention. Is there some sort of easy boolean I can change to make it keep my columns exactly as written?
The Yaml conversion is where the issue lies. To fix this you need to alias the column name in the YAML schema file IE: name: user_id as userId
Is it possible to have multiple slugs on one table in Doctrine?
I tried this in my yaml-file:
Article:
tableName: tst_article
actAs:
Sluggable:
unique: true
fields: [title]
canUpdate: true
Sluggable:
unique: true
fields: [text]
name: secondSlug
columns:
id:
type: integer(8)
primary: true
autoincrement: true
category_id:
type: integer(8)
title:
type: text(255)
text:
type: clob
But after generating the sql only the secondSlug was generated...
It is possible. In your table definition write:
public function setUp() {
parent::setUp();
$sluggable0 = new Doctrine_Template_Sluggable(array(
'fields' => array(0 => 'name'),
'unique' => true,
'canUpdate' => true
));
$this->actAs($sluggable0);
$sluggable1 = new Doctrine_Template_Sluggable(array(
'fields' => array(0 => 'native_name'),
'unique' => false,
'canUpdate' => false,
'name' => 'native_name_slug'
));
$this->actAs($sluggable1);
}
The problem is in YAML itself. You have something like this:
keyA:
keyB: value
keyB: value
What might be translated into:
array(
'keyA' => array(
'keyB' => 'value',
'keyB' => 'value'
)
);
So as you see there is definition of keyB and then keyB is overwritten with new value. So in your YAML file second definition overrides the first one.
How to solve that? I don't know, but I'll do some researches. Right now you're forced to declare your models in pure PHP.
Article:
tableName: tst_article
actAs:
Sluggable:
unique: true
fields: [title, text]
canUpdate: true
columns:
id:
type: integer(8)
primary: true
autoincrement: true
category_id:
type: integer(8)
title:
type: text(255)
text:
type: clob
Although changing libraries is not recommended, sometimes it's a necessary evil. A very small change allows you to declare Sluggable_1, Sluggable_2, etc. in your YAML.
--- a/lib/vendor/doctrine/Doctrine/Import/Builder.php
+++ b/lib/vendor/doctrine/Doctrine/Import/Builder.php
## -711,8 +711,10 ## class Doctrine_Import_Builder extends Doctrine_Builder
{
// find class matching $name
$classname = $name;
- if (class_exists("Doctrine_Template_$name", true)) {
- $classname = "Doctrine_Template_$name";
+ // HACK to allow multiple Sluggables
+ $classname = preg_replace('/_[0-9]+$/', '', $classname);
+ if (class_exists("Doctrine_Template_$classname", true)) {
+ $classname = "Doctrine_Template_$classname";
}
return " \$" . strtolower($name) . "$level = new $classname($option);". PHP_EOL;
}