21278 Posts in 5728 Topics by 2599 members
| Go to End | Next > | |
| Author | Topic: | 1313 Views |
-
CheckBox Fields in DataObjectManager

20 July 2011 at 12:10pm
Hello everyone.
I know how to implement checkbox fields with DataObjectManager. NO HasOneDataObjectManager .. NOT HasManyDataOb EITHER ManyManyDataOb.. because in my case I do not want any relation between objects, in other words to add options to a table not want to be added in the other tables on other pages, but if I want to have their own checks
-
Re: CheckBox Fields in DataObjectManager

21 July 2011 at 6:18am
If I'm understanding this correctly you just want a checkbox on a dataobject. All you need to do is a boolean your $db on the dataobject in question.
static $db=array(
"myOptionField" => "Boolean",
)'Then in the CMSFieldForPop add a new CheckboxField("myOptionField")
In the Database it will have a 1 if checked and 0 if not checked
-
Re: CheckBox Fields in DataObjectManager

21 July 2011 at 6:46pm
Just not really what I want to do is on my website only to see the records that I select the table (not the popup).
On the other hand I also thought hasManyDataObjectManager use because it meets the function above I am applying, but the problem is that I add the records in the tables on other pages. -
Re: CheckBox Fields in DataObjectManager

22 July 2011 at 1:20am
Maybe if you post your models it will help to better understand what you're trying to do. From what I understand is you're trying to associate a dataobject with a specific pagetype, and you only want the records associated with that page to render on the page. You may be building your $has_many relation wrong or calling that dataobject incorrectly and thats why its displaying all records on the data object, not those that should be associated with a particular page.
-
Re: CheckBox Fields in DataObjectManager

22 July 2011 at 5:48am Last edited: 22 July 2011 5:49am
look at the code
NuevoEquipo.php
class NuevoEquipo extends NuevaZona {
static $has_many = array(
'MiEquipo' => 'Equipos'
);function getCMSFields() {
$fields = parent::getCMSFields();
$playersTablefield = new DataObjectManager(
$this,
'MiEquipo',
'Equipos',
array(
'Nro_jugad' => 'Nro',
'Nombre' => 'Apellido y Nombre',
'PJ_jugad' => 'PJ',
'PG_jugad' => 'PG',
'PE_jugad' => 'PE',
'PP_jugad' => 'PP',
'Goles' => 'Goles',
'Prom' => 'Prom. G/P',
'Tarj_a' => 'Tarj. Amarillas',
'Tarj_r' => 'Tarj. Rojas'
),
'getCMSFields_forPopup'
);
$playersTablefield->setAddTitle( 'jugador' );$fields->addFieldToTab( 'Root.Content.Jugadores', $playersTablefield );
return $fields;
}}
..............................................................................................................................................................................................................
Equipos.php
class Equipos extends DataObject {
static $db = array(
'Nro_jugad' => 'Int',
'Nombre' => 'text',
'PJ_jugad' => 'Int',
'PG_jugad' => 'Int',
'PE_jugad' => 'Int',
'PP_jugad' => 'Int',
'Goles' => 'Int',
'Prom' => 'Int',
'Tarj_a' => 'Int',
'Tarj_r' => 'Int'
);static $default_sort = "Nro_jugad ASC";
static $has_one = array(
'Teams' => 'NuevoEquipo'
);function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new NumericField( 'Nro_jugad','Nro' ) );
$fields->push( new TextField( 'Nombre','Apellido y Nombre' ) );
$fields->push( new NumericField( 'PJ_jugad','PJ' ) );
$fields->push( new NumericField( 'PG_jugad','PG' ) );
$fields->push( new NumericField( 'PE_jugad','PE' ) );
$fields->push( new NumericField( 'PP_jugad','PP' ) );
$fields->push( new NumericField( 'Goles' ) );
$fields->push( new NumericField( 'Prom','Prom. G/P' ) );
$fields->push( new NumericField( 'Tarj_a','Tarj. Amarillas' ) );
$fields->push( new NumericField( 'Tarj_r','Tarj. Rojas' ) );
return $fields;
}}
As you can see in the picture "team" is a table with the names of players and other data, what I want is that this table only shows what I select (using checkboxfields ) in the table of the cms (see picture cms ).
Implement dataobjectmanager because otherwise the data will also create in the other teams and I do not want this to happen.
I'm sorry if I sound so good in English. -
Re: CheckBox Fields in DataObjectManager

22 July 2011 at 6:03am
OK See my original post. You need to add a Boolean Field to the Equipos DataObject then either write a new function that only returns records where that field equals 1 or filter it in the template with an <% if myOptionField = 1 %>
This way the front end will only show selected Equipos
-
Re: CheckBox Fields in DataObjectManager

22 July 2011 at 6:42am Last edited: 22 July 2011 6:44am
perfectly I understand u, add a Boolean Field to the db and filter it in the template. But how it would look this part?
how do I make it look in the cms (checkboxfield )?$playersTablefield = new DataObjectManager(
$this,
'MiEquipo',
'Equipos',
array(
'Nro_jugad' => 'Nro',
'Nombre' => 'Apellido y Nombre',
'PJ_jugad' => 'PJ',
'PG_jugad' => 'PG',
'PE_jugad' => 'PE',
'PP_jugad' => 'PP',
'Goles' => 'Goles',
'Prom' => 'Prom. G/P',
'Tarj_a' => 'Tarj. Amarillas',
'Tarj_r' => 'Tarj. Rojas'
),
'getCMSFields_forPopup'
); -
Re: CheckBox Fields in DataObjectManager

22 July 2011 at 6:56am
Basicially to call that field in the DOM it would look like
$playersTablefield = new DataObjectManager(
$this,
'MiEquipo',
'Equipos',
array(
'Nro_jugad' => 'Nro',
'Nombre' => 'Apellido y Nombre',
'PJ_jugad' => 'PJ',
'PG_jugad' => 'PG',
'PE_jugad' => 'PE',
'PP_jugad' => 'PP',
'Goles' => 'Goles',
'Prom' => 'Prom. G/P',
'Tarj_a' => 'Tarj. Amarillas',
'Tarj_r' => 'Tarj. Rojas',
'myOptionField' => 'myOptionField'
),
'getCMSFields_forPopup'
);But you need to define it in the DataObject
class Equipos extends DataObject {
static $db = array(
'Nro_jugad' => 'Int',
'Nombre' => 'text',
'PJ_jugad' => 'Int',
'PG_jugad' => 'Int',
'PE_jugad' => 'Int',
'PP_jugad' => 'Int',
'Goles' => 'Int',
'Prom' => 'Int',
'Tarj_a' => 'Int',
'Tarj_r' => 'Int',
'myOptionField' => 'Boolean'
);
static $default_sort = "Nro_jugad ASC";
static $has_one = array(
);function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new CheckboxField( 'myOptionField','Show in Front End' ) );
$fields->push( new NumericField( 'Nro_jugad','Nro' ) );
$fields->push( new TextField( 'Nombre','Apellido y Nombre' ) );
$fields->push( new NumericField( 'PJ_jugad','PJ' ) );
$fields->push( new NumericField( 'PG_jugad','PG' ) );
$fields->push( new NumericField( 'PE_jugad','PE' ) );
$fields->push( new NumericField( 'PP_jugad','PP' ) );
$fields->push( new NumericField( 'Goles' ) );
$fields->push( new NumericField( 'Prom','Prom. G/P' ) );
$fields->push( new NumericField( 'Tarj_a','Tarj. Amarillas' ) );
$fields->push( new NumericField( 'Tarj_r','Tarj. Rojas' ) );
return $fields;
}}
A list of field type can be found in the api documention http://api.silverstripe.org/2.4/forms/core/FormField.html and a list of the different data types here http://doc.silverstripe.org/sapphire/en/topics/data-types
| 1313 Views | ||
| Go to Top | Next > |


