Silverstripe Version:
3…
Question:
This is my first time upgrading a SS site; if you have any ideas of where I’m going wrong please share.
After running the silverstripe update tool I believe the namespaces were added to Page.php
I’m presuming the namespace Page is not global and therefore inaccessible. I read this post https://github.com/silverstripe/silverstripe-framework/issues/5844
use Sminnee\AppNamespace as App;
class Page extends App\Page { private static $hide_pagetype = true; }
class Page_Controller extends App\Page_Controller {}
However, I cannot see a \AppNamespace folder. So I’m not sure how implement the above.
There’s a post from today’s SS forum about Class ‘Page’ not found, however my /dev/build does not work and that is not the same issue I’m facing.
The environment is set to “dev”.
//Source: /Applications/MAMP/htdocs/trevorpan/mysite/code/Page.php
<?php
namespace Page;
use SiteTree;
use TextField;
use DropdownField;
use UploadField;
use ContentController;
use Requirements;
class Page extends SiteTree {
public static $db = array(
'Tagline' => 'Varchar(355)',
'ContentWidth' => 'Varchar(100)',
'SortID'=>'Int'
);
public static $has_one = array(
'FeaturedImage' => 'Image',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Main", new TextField('Tagline', 'Tagline'));
$fields->addFieldToTab("Root.Main", new DropdownField('ContentWidth', 'ContentWidth', array('One'=>'One', 'Two'=>'Two', 'Full'=>'Full')));
$fields->addFieldToTab("Root.Images", $featuredimage = UploadField::create('FeaturedImage', _t('FeaturedImage', 'FeaturedImage')));
$featuredimage->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
return $fields;
}
}
class Page_Controller extends ContentController {
/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* array (
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* );
* </code>
*
* @var array
*/
public static $allowed_actions = array (
);
public function init() {
parent::init();
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS('reset');
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}
}
**end of file**
//Source:/Applications/MAMP/htdocs/trevorpan/gallery/code/GalleryPage.php
<?php
class GalleryPage extends Page {
public static $many_many = array(
'Images' => 'Image'
);
public function Images() {
return $this->getManyManyComponents(
'Images',
'',
"\"GalleryPage_Images\".\"SortOrder\" ASC"
);
}
public function ImagesCaptions() {
$captions = GalleryPage_Images::get()
->where("\"GalleryPageID\" = '{$this->ID}'")
->map('ImageID', 'Caption')
->toArray();
}
public function getCMSFields() {
$fields = parent::getCMSFields();
$uploadField = new GalleryUploadField('Images', '');
$fields->addFieldToTab('Root.Images', $uploadField);
return $fields;
}
}
class GalleryPage_Controller extends Page_Controller {
public function init() {
parent::init();
Requirements::javascript('gallery/javascript/jquery-1.7.1.min.js');
Requirements::javascript('gallery/javascript/jquery.fancybox.js');
Requirements::javascript('gallery/javascript/GalleryPage.js');
Requirements::css('gallery/css/jquery.fancybox.css');
}
}
class GalleryPage_ImageExtension extends DataExtension {
public static $belongs_many_many = array(
'Pages' => 'Page'
);
public function getUploadFields() {
$fields = $this->owner->getCMSFields();
$fileAttributes = $fields->fieldByName('Root.Main.FilePreview')->fieldByName('FilePreviewData');
$fileAttributes->push(TextareaField::create('Caption', 'Caption:')->setRows(4));
$fields->removeFieldsFromTab('Root.Main', array(
'Title',
'Name',
'OwnerID',
'ParentID',
'Created',
'LastEdited',
'BackLinkCount',
'Dimensions'
));
return $fields;
}
public function Caption() {
//TODO: Make this more generic and not require a db query each time
$controller = Controller::curr();
$page = $controller->data();
$joinObj = GalleryPage_Images::get()
->where("\"GalleryPageID\" = '{$page->ID}' AND \"ImageID\" = '{$this->owner->ID}'")
->first();
return $joinObj->Caption;
}
}
class GalleryPage_Images extends DataObject {
static $db = array (
'GalleryPageID' => 'Int',
'ImageID' => 'Int',
'Caption' => 'Text',
'SortOrder' => 'Int'
);
}