2016-06-04 2 views
2

사이트를 구성 탭의 새 서버 양식 필드로 이동하는 것이 더 이상 데이터베이스에 저장되지 않으므로. 이전 서버 인 SilverStripe 2.3.3 및 PHP 5.2.17과 동일한 구성을 실행합니다. 로그 또는 PHP 오류가 발생하는 것을 볼 수 없습니다.실버 스트라이프 - cms 필드가 데이터베이스에 저장되지 않음

다른 필드가 저장 중이므로 문제가이 필드 집합에만 해당됩니다.

이 코드가이 기능을 담당한다고 가정합니다. 이 사람이 작동하지 않는 명백한 이유를 볼 수 있습니까 ?? $db 및 다른 정의에

Silverstripe 3.1에서
<?php 

class Product extends Page { 

public static $db = array(
    'ProductIntro' => 'Text', 
    'ProductPrice' => 'Text', 
    'SpecialOffer' => 'Boolean', 
    'HidePrice' => 'Boolean', 
    'OneMonthPrice' => 'Currency', 
    'ThreeMonthPrice' => 'Currency', 
    'FourMonthPrice' => 'Currency', 
    'SixMonthPrice' => 'Currency', 
    'OutrightPrice' => 'Currency', 
    'DeliveryPrice' => 'Currency', 
    'DefaultPrice' => 'Enum("OneMonthPrice,ThreeMonthPrice,FourMonthPrice,SixMonthPrice","OneMonthPrice")', 
    'VideoEmbedCode' => 'HTMLText' 
); 

public static $has_one = array(
    'ProductImage' => 'EnhancedImage' 
); 

public static $has_many = array(
    'ProductGalleryImages' => 'ProductGalleryImage', 
    'ProductDownloads' => 'ProductDownload' 
); 

public static $many_many = array(
    'RelatedProducts' => 'Product'        
); 

static $belongs_many_many = array(
    'IsRelatedProduct' => 'Product' 
); 


static $allowed_children = array(); 


public function getNextSibling() { 

    return DataObject::get("Product", "ParentID = $this->ParentID && Sort > $this->Sort && Status = 'Published'", "Sort ASC", null, 1); 
} 

public function getPreviousSibling() { 
    return DataObject::get("Product", "ParentID = $this->ParentID && Sort < $this->Sort && Status = 'Published'", "Sort DESC", null, 1); 
} 


public function SiblingProducts() { 
    if ($this->getField("ParentID")) { 

     return DataObject::get("Product", "ParentID = " . $this->getField("ParentID").' AND `SiteTree_Live`.ID != '.$this->getField("ID")); 
    } else return false; 
} 

public function SubCategory() { 
    if ($this->getField("ParentID")) { 
     return DataObject::get_one("ProductSubCategory", "`SiteTree_Live`.ID = " . $this->getField("ParentID")); 
    } else return false; 
} 

public function HasSubCategory() { 
    if ($this->SubCategory()) { 
     return true; 
    } else { 
     return false; 
    } 
} 

public function Category() { 
    if ($this->HasSubCategory()) { 
     $parent_id = $this->SubCategory()->getField("ParentID"); 
    } else { 
     $parent_id = $this->getField("ParentID"); 
    } 
    if ($parent_id) { 
     return DataObject::get("ProductCategory", "`SiteTree_Live`.ID = " . $parent_id); 
    } else return false; 
} 

public function IsFeaturedProduct() { 
    $hp = DataObject::get_one("ProductHomepage"); 
    if ($hp) { 
     if ($hp->FeaturedProduct()) { 
      if ($hp->FeaturedProduct()->getField('ID') && $hp->FeaturedProduct()->getField('ID') == $this->getField('ID')) return true; 
     } 
    } 
    return false; 
} 

public function IsCategorySpecial() { 

    if($this->parent()->CategoryFeaturedProductID == $this->ID) { 
     return true; 
    } 

    return false; 
} 


function onAfterWrite() { 
if (isset($_POST['AddedViaObjectManager']) && $_POST['SetPageToLive'] && $this->stagesDiffer('Stage','Live')) { 
    $this->Status = 'Published'; 
    $this->Publish('Stage', 'Live'); 
} 
parent::onAfterWrite(); 
} 

function getCMSFields_forPopup() { 
    $fields = new FieldSet(); 
    $fields->push(new TextField('Title', 'Product Title')); 
    $fields->push(new TextField('ProductIntro', 'Product Intro')); 
    $fields->push(new TextField('ProductPrice', 'Price ($)')); 
    $fields->push(new CheckboxField('SpecialOffer', 'This Product is a Special Offer')); 
    $record = DataObject::get('ProductSubCategory', ""); 
    if ($record) { 
     $map = $record->toDropDownMap('ID', 'Title'); 
    } else { 
     $map = array(); 
    } 
    $fields->push(new DropdownField('ParentID','Sub Category',$map)); 
    $fields->push(new SimpleHTMLEditorField('Content', 'Content')); 
    $fields->push(new DropdownField('SetPageToLive','After Update, Set Product Page To:',array('1'=>'Live','0'=>'Draft'))); 
    $fields->push(new FileIFrameField('ProductImage')); 
    $fields->push(new HiddenField('AddedViaObjectManager','AddedViaObjectManager',1)); 
    return $fields; 
} 

function getCMSFields() { 
    $fields = parent::getCMSFields(); 

    $product = new VerticalTabSet(
     new VerticalTab('Configuration',array(
      new LiteralField("ConfDescription","<br /><em>Product pages support a range of additional features such as pricing.</em><br /><br />"), 
      new TextField('ProductIntro', 'Intro Text'), 
      new TextField('ProductPrice', 'From Text (Formerly Price)'), 
      new CheckboxField("HidePrice","Hide Price"), 
      new CheckboxField("SpecialOffer","This Product is currently on special."), 
      new LiteralField("ldiv","<br /><br /><h2>Pricing</h2>"), 
      new CurrencyField("OneMonthPrice", "One Month Hire Price"), 
      new CurrencyField("ThreeMonthPrice", "Three Month Hire Price"), 
      new CurrencyField("FourMonthPrice", "Four Month Hire Price"), 
      new CurrencyField("SixMonthPrice", "Six Month Hire Price"), 
      new CurrencyField("OutrightPrice", "Outright Purchase Price"), 
      new CurrencyField("DeliveryPrice", "Delivery Price"), 
      new DropDownField("DefaultPrice", "Selected Pricing Option", array('OneMonthPrice'=>'1 Month','ThreeMonthPrice'=>'3 Month','FourMonthPrice'=>'4 Month','SixMonthPrice'=>'6 Month')) 
     )), 
     new VerticalTab('RelatedProducts',array(
      new LiteralField("RelatedDescription","<br /><em>Related products are displayed on a product page to direct users to other options.</em><br /><br />"), 
      new ManyManyDataObjectManager(
       $this, // Controller 
       'RelatedProducts', // Source name 
       'Product', // Source class 
       array(
        'Title' => 'Title' 
       ), // Headings 
       'getCMSFields_forPopup' // Detail fields (function name or FieldSet object) 
      ) 
     )), 
     new VerticalTab('Images',array(
      new LiteralField("ImageryDescription","<br /><em>The Main Image is used as the default image for this product.</em><br /><br />"), 
      new FileIFrameField('ProductImage', 'Main Image'), 
      new LiteralField ("ProdImages",'<br /><h4 style="margin-bottom:0px;padding-bottom:0px;">Upload Product Images</h4><br /><em>Supports all image types, however web images are recommended.</em><br /><br />'), 
      new ImageDataObjectManager(
       $this, // Controller 
       'ProductGalleryImages', // Source name 
       'ProductGalleryImage', // Source class 
       'Image', // File name on DataObject 
       array(
        'Title' => 'Title' 
       ), // Headings 
       'getCMSFields_forPopup' // Detail fields (function name or FieldSet object) 
      ) 
     )), 
     new VerticalTab('Downloads',array(
      new LiteralField("ImageryDescription","<br /><em>Add files users can download.</em><br /><br />"), 
      new FileDataObjectManager(
       $this, // Controller 
       'ProductDownloads', // Source name 
       'ProductDownload', // Source class 
       'File', // File name on DataObject 
       array(
        'Title' => 'Title' 
       ), // Headings 
       'getCMSFields_forPopup' // Detail fields (function name or FieldSet object) 
      ) 
     )), 
     new VerticalTab('Video',array(
      new LiteralField("VideoDescription","<br /><em>Add the embed code here.</em><br /><br />"), 
      new TextareaField('VideoEmbedCode', 'Video Embed Code', 4) 
     )) 
); 

    $product->setOpenTab('Configuration'); 

    //$fields->addFieldToTab("Root.Content.Product",$product); 

    $fields->insertAfter(new Tab('Configuration',$product),'Main'); 



    //$fields->insertAfter(new Tab('Related Products',$product_rel),'Main'); 



    //$main = $fields->fieldByName('Main'); 

    //$main->title = 'Product Details'; 


    return $fields; 
} 

function HirePrices() { 
    $prices = new DataObjectSet(); 

    $keys = array(
    'OneMonthPrice' => 'One Month', 
    'ThreeMonthPrice' => 'Three Month', 
    'FourMonthPrice' => 'Four Month', 
    'SixMonthPrice' => 'Six Month', 
    ); 
    $f = true; 
    foreach($keys as $price_item => $title) { 
     if ($this->$price_item > 0) { 
      $p = $this->$price_item; 
      $prices->push(new ArrayData(array(
       'price' => $p, 
       'nice_price' => '$'.number_format($p,2), 
       'title' => $title, 
       'First' => $f, 
       'IsDefault' => ($this->DefaultPrice == $price_item) ? true : false 
      ))); 
      $f = false; 
     } 
    } 

    return ($prices) ? $prices : false; 

} 

} 

class Product_Controller extends Page_Controller { 

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

} 

function Category() { 
    return $this->data()->Category(); 
} 

function SiblingProducts() { 
    return $this->data()->SiblingProducts(); 
} 



} 

?> 
+0

페이지라면 여기에 도움을주기위한 열쇠가 될 getCMSFields 함수가 있다고 가정합니다. 다른 방법을 사용하면 다른 수정 양식을 사용하고 있는지 명확히 할 수 있습니까? ModelAdmin. – Barry

+0

'/ dev/build? flush = all'을 실행하면 어떻게됩니까? – jbe

+0

Silverstripe 3.x는 PHP 5.3 이상을 실행해야합니다. PHP 5.2는 완전히 구식입니다. 서버를 최신 PHP 5.6으로 업데이트해야합니다. PHP 5.2는 이전 버전보다 훨씬 빠르게 실행됩니다. 5.2 – wmk

답변

3

private static 변수로 선언해야합니다, 그래서 그들은 설정 시스템에 의해 캐시 (및 덮어 쓰기) 할 수 있습니다.

<?php 

class Product extends Page { 

private static $db = array(
... 
); 

이 또한 module that upgrades your code for you이며 2.4 코드를 3.x에서 실행 된 가져 오기위한 작업의 90 %를 않습니다

3

사람들에게 격려하는 것이 유익한 조언이지만, OP에는 현재로서는 그렇게하지 않는 이유가있는 것 같습니다.

서버 구성과 PHP 버전이 같으면 확인 -하지만 데이터베이스는 어떻게됩니까? 이전 호스트에서 사용하고 있던 RDBMS 및 버전과 새 호스트에서 사용중인 버전에 대해서는 언급하지 않았습니다.

첫 번째 문제는 무엇입니까? 실제로 서버 오류가 기록되지 않았습니까? 새 설정에서 php.ini 파일이 기존 서버의 파일과 일치합니까? dev 또는 prod에서만이 문제가 발생합니까? dev env에서 error_reportingE_ALLdislay_errors에서 on으로 설정하는 것이 좋습니다. php.ini에서 로깅 오류가 발생하는 위치를 확인하십시오. 이것은 서버의 syslog, 아파치 로그 또는 전용 php_errors 로그 파일 일 수 있습니다. 이 파일들 각각이 읽기 + 쓰기가 가능한지 확인하십시오. 그렇지 않으면 아무것도 기록되지 않습니다.

데이터 모델을 내려다보고 DataObject::get()에 대한 일부 호출을 볼 수 있습니다. 일부 원시 SQL은 SQL WHERE 절로 삽입되어 있습니다. 괜찮습니다. 그러나 일부는 일관성 없게 이스케이프 처리 된 것 같습니다 (적어도 다른 섹션에서 벗어난 방법과는 다릅니다). getPreviousSibling()getNextSibling(). RDBMS (MySQL, Postgres 등)가 들어오는 쿼리를 어떻게 구성하고 이스케이프해야하는지에 대한 기대치가 다른 버전 일 수 있습니까?

RDBMS에 대한 쿼리 로그를 확인 했습니까? 그것은 무엇을 말하는가?

관련 문제