[Add name spaced file composer.json to mysite root (will be different for silverstripe 4.1)]
Hi outdoorsnz, when performing in terminal:
./vendor/bin/sake dev/tasks/MigrateFileTask
I’m getting an error in my IDE that says, “Cannot declare class SilverStripe\trevorpan\Page because the name is already in use.”
It happens intermittently with the PageController class, too. When you say silverstripe/myproject I’m typing the folder name in htdocs “trevorpan” (my own website) would this be correct?
I’ve added a composer.json file as you say:
{
“name”: “silverstripe/trevorpan”,
“description”: “Code,
“license”: “BSD-3-Clause”,
“authors”: [
{
“name”: “Your Name”,
“email”: "email@someemail.com”
}
],
“require”: {
“silverstripe/recipe-cms”: “^1.0”
},
“autoload”: {
“psr-4”: {
“SilverStripe\trevorpan\”: “mysite/”
}
}
}
This is the page.php file:
?php
namespace SilverStripe\trevorpan;
use Page;
use PageController;
use SilverStripe\CMS\Model\SiteTree;
use PackageTextField;
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;
}
private static $table_name = "MyDataObject";
//private static $db = [];
//private static $has_one = [];
}
class PageController 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');
}
}
thank you,
Trevor