Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

DataObject extending, GridField using


Reply

3 Posts   895 Views

Avatar
hopkins

21 November 2012 at 5:51am (Last edited: 21 November 2012 5:54am), Community Member, 3 Posts

Hi!

i'm developing site based on silverstripe, and i really like this cms, but there is a problem with dataobjects

here code

<?php
class Portfolio extends Page {

   public static $db = array(
   );

   public static $has_one = array(
   );

   public static $has_many = array(
      'Profiles' => 'Profile'
   );

   public function getCMSFields() {
      $fields = parent::getCMSFields();
      //$profilesField = new ComplexTableField($this, 'Profiles', 'Profile');
      
      $config = GridFieldConfig_RelationEditor::create();
// Set the names and data for our gridfield columns
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Title' => 'Title',
         'Year' => 'Year'
));

$profilesField = new GridField(
'Profiles', // Field name
'Profiles', // Field title
Profile::get(),
$config
);

      $fields->addFieldToTab('Root.Profiles', $profilesField);
      
      return $fields;
   }
}
class Portfolio_Controller extends Page_Controller {

   public static $allowed_actions = array (
   );

   public function init() {
      parent::init();
   }
}

and dataobject code

<?php
   class Profile extends DataObject {
      static $db = array(
         'Title' => 'Text',
         'Year' => 'Text'
      );
      static $has_one = array (
         'Portfolio' => 'Portfolio',
         'ProfileImage' => 'Image'
      );
      
      function getCMSFields() {
         $fields = new FieldSet(
                new TextField('Title', 'Заголовок'),
                new TextField('Year', 'Год выпуска'),
                new UploadField('ProfileImage')
               );
         return $fields;
      }
   }
?>

so, when i'm trying to use GridField to add Profiles to portfolio, when i get to Portfolio editor i recieve

{"Content":"<div id=\"pages-controller-cms-content\" class=\"cms-content center cms-tabset CMSPageEditController CMSMain LeftAndMain\" data-layout-type=\"border\" data-pjax-fragment=\"Content\" data-ignore-tab-state=\"true\">\n\n\t<div class=\"cms-content-header north\">\n\t\t<div class=\"cms-content-header-info\">\n\t\t\t<h2>\n\t\t\t\t<div class=\"breadcrumbs-wrapper\" data-pjax-fragment=\"Breadcrumbs\">\n\n\t\n\t\t<span class=\"section-icon icon icon-16 icon-cmspagescontroller\"><\/span>\n\t\n\n\t\n\t\t\n\t\t\t<a class=\"cms-panel-link crumb\" href=\"admin\/pages\/\">Edit Page<\/a>\n\t\t\t<span class=\"sep\">\/<\/span>\n\t\t\n\t\n\t\t\n\t\t\t<span class=\"cms-panel-link crumb last\">\u041f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e<\/span>\n\t\t\n\t\n<\/div>\n\n\t\t\t<\/h2>\n\t\t<\/div>\n\t\n\t\t<div class=\"cms-content-header-tabs\">\n\t\t\t<ul>\n\t\t\t\t<li class=\"content-treeview ui-tabs-selected\">\n\t\t\t\t\t<a href=\"admin\/pages\/edit\/show\/9\" class=\"cms-panel-link\" title=\"Form_EditForm\" data-href=\"admin\/pages\/edit\/show\/9\">\n\t\t\t\t\t\tContent\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/li>\n\t\t\t\t<li class=\"content-listview\">\n\t\t\t\t\t<a href=\"admin\/pages\/settings\/show\/9\" class=\"cms-panel-link\" title=\"Form_EditForm\" data-href=\"admin\/pages\/settings\/show\/9\">\n\t\t\t\t\t\tSettings\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/li>\n\t\t\t\t<li class=\"content-listview\">\n\t\t\t\t\t<a href=\"admin\/pages\/history\/show\/9\" class=\"cms-panel-link\" title=\"Form_EditForm\" data-href=\"admin\/pages\/history\/show\/9\">\n\t\t\t\t\t\tHistory\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/li>\n\t\t\t<\/ul>\n\t\t<\/div>\n\t<\/div>\n\n\t<div class=\"cms-content-tools west cms-panel cms-panel-layout\" data-expandOnClick=\"true\" data-layout-type=\"border\" id=\"cms-content-tools-CMSMain\">\n\t<div class=\"cms-panel-content center\">\n\t\t<div class=\"cms-content-view cms-tree-view-sidebar cms-panel-deferred\" id=\"cms-content-treeview\" data-url=\"admin\/pages\/treeview\">\n\t\t\t\n\t\t<\/div>\n\t<\/div>\n\t<div class=\"cms-panel-content-collapsed\">\n\t\t<h3 class=\"cms-panel-header\">Spectrum<\/h3>\n\t<\/div>\n<\/div>\n\n\t<form id=\"Form_EditForm\" action=\"admin\/pages\/edit\/EditForm\" method=\"post\" enctype=\"application\/x-www-form-urlencoded\" class=\"cms-edit-form center CMSPageEditController CMSMain LeftAndMain\" data-pjax-fragment=\"CurrentForm\" data-layout-type=\"border\">\n\n\t<div class=\"cms-content-fields center\">\n\t\t\n\t\t<p id=\"Form_EditForm_error\" class=\"message \" style=\"display: none\"><\/p>\n\t\t\n\n\t\t<fieldset>\n\t\t\t \n\t\t\t\n\t\t\t\t<div id=\"Root\" class=\"ss-tabset tabset\">\n\t<ul>\n\t\n\t\t<li class=\"first \"><a href=\"#Root_Main\" id=\"tab-Root_Main\">Main Content<\/a><\/li>\n\t\n\t\t<li class=\"last \"><a href=\"#Root_Profiles\" id=\"tab-Root_Profiles\">Profiles<\/a><\/li>\n\t\n\t<\/ul>\n\n\t\n\t\t\n\t\t\t<div id=\"Root_Main\" class=\"tab \">\n\t\t\t\t\n\t\t\t\t\t<div id=\"Title\" class=\"field text\">\n\t<label class=\"left\" for=\"Form_EditForm_Title\">Page name<\/label>\n\t<div class=\"middleColumn\">\n\t\t<input type=\"text\" name=\"Title\" value=\"\u041f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e\" class=\"text\" id=\"Form_EditForm_Title\" \/>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\t\t\n\t\t\t\t\t<div id=\"URLSegment\" class=\"field text urlsegment\">\n\t<label class=\"left\" for=\"Form_EditForm_URLSegment\">URL Segment<\/label>\n\t<div class=\"middleColumn\">\n\t\t<span class=\"prefix\">http:\/\/spectrum19.ru\/<\/span><input type=\"text\" name=\"URLSegment\" value=\"portfolio\" class=\"text urlsegment\" id=\"Form_EditForm_URLSegment\" \/>\n\n<p class=\"help\"> Special characters are automatically converted or removed.<\/p>\n\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\t\t\n\t\t\t\t\t<div id=\"MenuTitle\" class=\"field text\">\n\t<label class=\"left\" for=\"Form_EditForm_MenuTitle\">Navigation label<\/label>\n\t<div class=\"middleColumn\">\n\t\t<input type=\"text\" name=\"MenuTitle\" value=\"\u041f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e\" class=\"text\" id=\"Form_EditForm_MenuTitle\" \/>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\t\t\n\t\t\t\t\t<div id=\"Content\" class=\"field htmleditor stacked\">\n\t<label class=\"left\" for=\"Form_EditForm_Content\">Content<\/label>\n\t<div class=\"middleColumn\">\n\t\t<textarea name=\"Content\" value=\"\" class=\"htmleditor stacked\" id=\"Form_EditForm_Content\" rows=\"30\" cols=\"20\" tinymce=\"true\" style=\"width: 97%; height: 480px\"><\/textarea>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\t\t\n\t\t\t\t\t<div id=\"Form_EditForm_Metadata\" class=\"ss-toggle ss-toggle-start-closed togglecomposite\">\n\t<h4><a href=\"#\">Metadata<\/a><\/h4>\n\t<div>\n\t\t\n\t\t\t<div id=\"MetaTitle\" class=\"field text\">\n\t<label class=\"left\" for=\"Form_EditForm_MetaTitle\">Meta Title<\/label>\n\t<div class=\"middleColumn\">\n\t\t<input type=\"text\" name=\"MetaTitle\" class=\"text\" id=\"Form_EditForm_MetaTitle\" \/>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\n\t\t\t<div id=\"MetaKeywords\" class=\"field textarea\">\n\t<label class=\"left\" for=\"Form_EditForm_MetaKeywords\">Meta Keywords<\/label>\n\t<div class=\"middleColumn\">\n\t\t<textarea name=\"MetaKeywords\" class=\"textarea\" id=\"Form_EditForm_MetaKeywords\" rows=\"5\" cols=\"20\"><\/textarea>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\n\t\t\t<div id=\"MetaDescription\" class=\"field textarea\">\n\t<label class=\"left\" for=\"Form_EditForm_MetaDescription\">Meta Description<\/label>\n\t<div class=\"middleColumn\">\n\t\t<textarea name=\"MetaDescription\" class=\"textarea\" id=\"Form_EditForm_MetaDescription\" rows=\"5\" cols=\"20\"><\/textarea>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\n\t\t\t<div id=\"ExtraMeta\" class=\"field textarea\">\n\t<label class=\"left\" for=\"Form_EditForm_ExtraMeta\">Custom Meta Tags<\/label>\n\t<div class=\"middleColumn\">\n\t\t<textarea name=\"ExtraMeta\" class=\"textarea\" id=\"Form_EditForm_ExtraMeta\" rows=\"5\" cols=\"20\"><\/textarea>\n\t<\/div>\n\t\n\t\n<\/div>\n\t\t\n\t<\/div>\n<\/div>\n\n\t\t\t\t\n\t\t\t<\/div>\n\t\t\n\t\n\t\t\n\t\t\t<div id=\"Root_Profiles\" class=\"tab \">\n\t\t\t\t\n\t\t\t\t\t<fieldset class=\"grid ss-gridfield ss-gridfield field\" id=\"Form_EditForm_Profiles\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\" data-name=\"Profiles\"><div class=\"addNewGridFieldButton\">\n\t<div class=\"left\"><a href=\"admin\/pages\/edit\/EditForm\/field\/Profiles\/item\/new\" class=\"action action-detail ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link\" data-icon=\"add\">\nAdd Profile\n<\/a>\n<div class=\"add-existing-autocompleter\">\n\t\n\t<span><input type=\"text\" name=\"gridfield_relationsearch\" class=\"text relation-search no-change-track\" id=\"gridfield_relationsearch\" data-search-url=\"&#039;admin\/pages\/edit\/EditForm\/field\/Profiles\/search&#039;\" placeholder=\"Find Profils by Title\" \/><\/span>\n\t\n\t<span>\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb4776f9af5_59611330\" value=\"Find\" class=\"action action\" id=\"action_gridfield_relationfind\" data-icon=\"relationfind\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\tFind\n\t<\/button>\n<\/span>\n\t\n\t<span>\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477701849_76818090\" value=\"Link Existing\" class=\"action action\" id=\"action_gridfield_relationadd\" disabled=\"disabled\" data-icon=\"chain--plus\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\tLink Existing\n\t<\/button>\n<\/span>\n\t\n<\/div><\/div>\n\t<div class=\"right\"><\/div>\n<\/div>\n<input type=\"hidden\" name=\"Profiles[GridState]\" value=\"{&quot;GridFieldAddRelation&quot;:[],&quot;GridFieldSortableHeader&quot;:{&quot;SortColumn&quot;:[]},&quot;GridFieldFilterHeader&quot;:{&quot;Columns&quot;:[]},&quot;GridFieldPaginator&quot;:{&quot;currentPage&quot;:1},&quot;GridFieldSearchRelation&quot;:[]}\" class=\"gridstate\" id=\"Profiles-GridState\" \/><table class=\"ss-gridfield-table\" cellpadding=\"0\" cellspacing=\"0\"><thead><tr class=\"title\">\n\t<th colspan=\"3\">\n\t\t<h2>Profiles<\/h2>\n\t\t<div class=\"right\"><\/div>\n\t\t<div class=\"left\"><\/div>\n\t<\/th>\n<\/tr>\n<tr class=\"sortable-header\">\n\t\n\t\t<th class=\"main col-action_SetOrderTitle\">\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477718293_97493828\" value=\"\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\" class=\"action action ss-gridfield-sort\" id=\"action_SetOrderTitle\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\n\t<\/button>\n<\/th>\n\t\n\t\t<th class=\"main col-action_SetOrderYear\">\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477720269_18331557\" value=\"\u0413\u043e\u0434 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\" class=\"action action ss-gridfield-sort\" id=\"action_SetOrderYear\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\u0413\u043e\u0434 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\n\t<\/button>\n<\/th>\n\t\n\t\t<th class=\"main col-Actions\"><button name=\"showFilter\" class=\"ss-gridfield-button-filter trigger\"><\/button><\/th>\n\t\n<\/tr>\n\n<tr class=\"filter-header\" style=\"display:none;\">\n\t\n\t<th class=\"extra\"><div class=\"fieldgroup nolabel\" >\n\t\n\t\t<div class=\"fieldgroup-field first odd\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t<input type=\"text\" name=\"filter[Title]\" class=\"text ss-gridfield-sort no-change-track nolabel\" id=\"filter-Title\" placeholder=\"Filter by \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a\" \/>\n<\/div>\n\t\t<\/div>\n\t\n\t\t<div class=\"fieldgroup-field last even\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477750638_05895596\" class=\"action action ss-gridfield-button-reset nolabel\" id=\"action_reset_Profile_Title\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\n\t<\/button>\n\n<\/div>\n\t\t<\/div>\n\t\n<\/div><\/th>\n\t\n\t<th class=\"extra\"><div class=\"fieldgroup nolabel\" >\n\t\n\t\t<div class=\"fieldgroup-field first odd\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t<input type=\"text\" name=\"filter[Year]\" class=\"text ss-gridfield-sort no-change-track nolabel\" id=\"filter-Year\" placeholder=\"Filter by \u0413\u043e\u0434 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\" \/>\n<\/div>\n\t\t<\/div>\n\t\n\t\t<div class=\"fieldgroup-field last even\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb47776f700_00747536\" class=\"action action ss-gridfield-button-reset nolabel\" id=\"action_reset_Profile_Year\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\n\t<\/button>\n\n<\/div>\n\t\t<\/div>\n\t\n<\/div><\/th>\n\t\n\t<th class=\"extra\"><div class=\"fieldgroup filter-buttons no-change-track nolabel\" >\n\t\n\t\t<div class=\"fieldgroup-field first odd\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477783499_52346646\" class=\"action action ss-gridfield-button-filter nolabel\" id=\"action_filter_Profile_Actions\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\n\t<\/button>\n\n<\/div>\n\t\t<\/div>\n\t\n\t\t<div class=\"fieldgroup-field last even\">\n\t\t\t<div class=\"fieldholder-small\">\n\t\n\t\n\t\n\t<button name=\"action_gridFieldAlterAction?StateID=50abb477792c05_15768302\" class=\"action action ss-gridfield-button-close nolabel\" id=\"action_reset_Profile_Actions\" data-url=\"admin\/pages\/edit\/EditForm\/field\/Profiles\">\n\t\t\n\t<\/button>\n\n<\/div>\n\t\t<\/div>\n\t\n<\/div><\/th>\n\t\n<\/tr><\/thead>\n\n<tbody class=\"ss-gridfield-items\"><tr class=\"ss-gridfield-item ss-gridfield-no-items\"><td colspan=\"3\">No items found<\/td><\/tr><\/tbody><\/table><\/fieldset>\n\t\t\t\t\n\t\t\t<\/div>\n\t\t\n\t\n<\/div>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"ClassName\" value=\"Portfolio\" class=\"hidden\" id=\"Form_EditForm_ClassName\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"ParentID\" value=\"0\" class=\"hidden\" id=\"Form_EditForm_ParentID\" \/>\n\n\t\t\t\n\t\t\t\t<div class=\"cms-navigator\">\n\t<a href=\"#\" class=\"ss-ui-button cms-preview-toggle-link\" data-icon=\"preview\">\n\t\t&laquo; Edit\n\t<\/a>\n\t<ul class=\"cms-preview-states\">\n\t\t\n\t\t\t<li class=\"\"><a href=\"http:\/\/spectrum19.ru\/portfolio\/?stage=Stage\">Draft Site<\/a>\n\t\t\t\t<span class=\"cms-preview-watermark\">Draft Site<\/span>\n\t\t\t<\/li>\n\t\t\n\t\t\t<li class=\" active\"><a href=\"http:\/\/spectrum19.ru\/portfolio\/?stage=Live\">Published Site<\/a>\n\t\t\t\t<span class=\"cms-preview-watermark\">Published Site<\/span>\n\t\t\t<\/li>\n\t\t\n\t<\/ul>\n<\/div>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"SecurityID\" value=\"6cbab1f891307d590052f4c09f3c6456f1ef78ae\" class=\"hidden\" id=\"Form_EditForm_SecurityID\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"ID\" value=\"9\" class=\"hidden nolabel\" id=\"Form_EditForm_ID\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"AbsoluteLink\" class=\"hidden nolabel\" id=\"Form_EditForm_AbsoluteLink\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"LiveLink\" value=\"http:\/\/spectrum19.ru\/portfolio\/?stage=Live\" class=\"hidden\" id=\"Form_EditForm_LiveLink\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"StageLink\" value=\"http:\/\/spectrum19.ru\/portfolio\/?stage=Stage\" class=\"hidden\" id=\"Form_EditForm_StageLink\" \/>\n\n\t\t\t\n\t\t\t\t<input type=\"hidden\" name=\"TreeTitle\" value=\"&lt;span class=&quot;jstree-pageicon&quot;&gt;&lt;\/span&gt;&lt;span class=&quot;item&quot;&gt;\u041f\u043e\u0440\u0442\u0444\u043e\u043b\u0438\u043e&lt;\/span&gt;\" class=\"hidden nolabel\" id=\"Form_EditForm_TreeTitle\" \/>\n\n\t\t\t\n\t\t\t<div class=\"clear\"><!-- --><\/div>\n\t\t<\/fieldset>\n\t<\/div>\n\n\t<div class=\"cms-content-actions south\">\n\t\t\n\t\t<div class=\"Actions\">\n\t\t\t\n\t\t\t\t<fieldset class=\"CompositeField composite ss-ui-buttonset nolabel \">\n\t\n\t\n\t\n\t\t\n\t\t\t\n\t<button name=\"action_unpublish\" value=\"Unpublish\" class=\"action action ss-ui-action-destructive\" id=\"Form_EditForm_action_unpublish\" title=\"Remove this page from the published site\" data-icon=\"unpublish\">\n\t\tUnpublish\n\t<\/button>\n\n\t\t\n\t\n\t\t\n\t\t\t\n\t<button name=\"action_delete\" value=\"Delete draft\" class=\"action action delete ss-ui-action-destructive\" id=\"Form_EditForm_action_delete\" data-icon=\"decline\">\n\t\tDelete draft\n\t<\/button>\n\n\t\t\n\t\n\t\t\n\t\t\t\n\t<button name=\"action_save\" value=\"Save Draft\" class=\"action action\" id=\"Form_EditForm_action_save\" data-icon=\"addpage\">\n\t\tSave Draft\n\t<\/button>\n\n\t\t\n\t\n<\/fieldset>\n\t\t\t\n\t\t\t\t\n\t<button name=\"action_publish\" value=\"Save &amp; Publish\" class=\"action action ss-ui-action-constructive\" id=\"Form_EditForm_action_publish\" data-icon=\"accept\">\n\t\tSave & Publish\n\t<\/button>\n\n\t\t\t\n\t\t\t\n\t\t\t<a href=\"\/portfolio\/?stage=Stage\" class=\"cms-preview-toggle-link ss-ui-button\" data-icon=\"preview\">\n\t\t\t\tPreview &raquo;\n\t\t\t<\/a>\n\t\t\t\n\t\t<\/div>\n\t\t\n\t<\/div>\n<\/form>\n\t\n<\/div>"

with no } at the end

can u tell me what i'm doing wrong???

Avatar
hopkins

23 November 2012 at 3:56am Community Member, 3 Posts

problem is in server configuration, the same thing on fresh LAMP platform works well, but i can't find problem...

Avatar
hopkins

23 November 2012 at 3:12pm Community Member, 3 Posts

lol, i should read tutorial more carefull