mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
classes psr2
This commit is contained in:
parent
2414eaeafd
commit
4c7a068b28
@ -115,7 +115,8 @@ The restriction is enforced through the `$allowed_children` directive.
|
||||
```php
|
||||
use Page;
|
||||
|
||||
class ProjectsHolder extends Page {
|
||||
class ProjectsHolder extends Page
|
||||
{
|
||||
private static $allowed_children = [
|
||||
'Project'
|
||||
];
|
||||
|
@ -20,8 +20,8 @@ Let's look at a simple example:
|
||||
**mysite/code/Player.php**
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'PlayerNumber' => 'Int',
|
||||
@ -77,8 +77,8 @@ system. Instead, it will generate a new `ID` by adding 1 to the current maximum
|
||||
**mysite/code/Player.php**
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'PlayerNumber' => 'Int',
|
||||
@ -570,7 +570,8 @@ For instance, the below model will be stored in the table name `BannerImage`
|
||||
|
||||
```php
|
||||
namespace SilverStripe\BannerManager;
|
||||
class BannerImage extends \DataObject {
|
||||
class BannerImage extends \DataObject
|
||||
{
|
||||
private static $table_name = 'BannerImage';
|
||||
}
|
||||
```
|
||||
@ -660,8 +661,8 @@ Define the default values for all the `$db` fields. This example sets the "Statu
|
||||
whenever a new object is created.
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $defaults = [
|
||||
"Status" => 'Active',
|
||||
@ -685,12 +686,12 @@ time.
|
||||
For example, suppose we have the following set of classes:
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class NewsPage extends Page {
|
||||
class NewsPage extends Page
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Summary' => 'Text'
|
||||
|
@ -16,8 +16,8 @@ A 1-to-1 relation creates a database-column called "`<relationship-name>`ID", in
|
||||
"TeamID" on the "Player"-table.
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Varchar'
|
||||
@ -27,8 +27,8 @@ A 1-to-1 relation creates a database-column called "`<relationship-name>`ID", in
|
||||
'Players' => 'Player'
|
||||
];
|
||||
}
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $has_one = [
|
||||
"Team" => "Team",
|
||||
@ -75,20 +75,22 @@ To specify that a has_one relation is polymorphic set the type to 'DataObject'.
|
||||
Ideally, the associated has_many (or belongs_to) should be specified with dot notation.
|
||||
|
||||
```php
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
private static $has_many = [
|
||||
"Fans" => "Fan.FanOf"
|
||||
];
|
||||
}
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
private static $has_many = [
|
||||
"Fans" => "Fan.FanOf"
|
||||
];
|
||||
}
|
||||
|
||||
// Type of object returned by $fan->FanOf() will vary
|
||||
class Fan extends DataObject {
|
||||
class Fan extends DataObject
|
||||
{
|
||||
|
||||
// Generates columns FanOfID and FanOfClass
|
||||
private static $has_one = [
|
||||
@ -116,8 +118,8 @@ available on both ends.
|
||||
</div>
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Varchar'
|
||||
@ -127,8 +129,8 @@ available on both ends.
|
||||
'Players' => 'Player'
|
||||
];
|
||||
}
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $has_one = [
|
||||
"Team" => "Team",
|
||||
@ -157,16 +159,16 @@ you will get an instance of [HasManyList](api:SilverStripe\ORM\HasManyList) rath
|
||||
To specify multiple `$has_many` to the same object you can use dot notation to distinguish them like below:
|
||||
|
||||
```php
|
||||
|
||||
class Person extends DataObject {
|
||||
class Person extends DataObject
|
||||
{
|
||||
|
||||
private static $has_many = [
|
||||
"Managing" => "Company.Manager",
|
||||
"Cleaning" => "Company.Cleaner",
|
||||
];
|
||||
}
|
||||
|
||||
class Company extends DataObject {
|
||||
class Company extends DataObject
|
||||
{
|
||||
|
||||
private static $has_one = [
|
||||
"Manager" => "Person",
|
||||
@ -201,15 +203,15 @@ Similarly with `$has_many`, dot notation can be used to explicitly specify the `
|
||||
This is not mandatory unless the relationship would be otherwise ambiguous.
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $has_one = [
|
||||
'Coach' => 'Coach'
|
||||
];
|
||||
}
|
||||
|
||||
class Coach extends DataObject {
|
||||
class Coach extends DataObject
|
||||
{
|
||||
|
||||
private static $belongs_to = [
|
||||
'Team' => 'Team.Coach'
|
||||
@ -251,8 +253,8 @@ config to add extra columns.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
private static $many_many = [
|
||||
"Supporters" => "Supporter",
|
||||
];
|
||||
@ -262,8 +264,8 @@ config to add extra columns.
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
class Supporter extends DataObject {
|
||||
class Supporter extends DataObject
|
||||
{
|
||||
|
||||
private static $belongs_many_many = [
|
||||
"Supports" => "Team",
|
||||
@ -294,8 +296,8 @@ or child record.
|
||||
The syntax for `belongs_many_many` is unchanged.
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
private static $many_many = [
|
||||
"Supporters" => [
|
||||
'through' => 'TeamSupporter',
|
||||
@ -304,14 +306,14 @@ The syntax for `belongs_many_many` is unchanged.
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
class Supporter extends DataObject {
|
||||
class Supporter extends DataObject
|
||||
{
|
||||
private static $belongs_many_many = [
|
||||
"Supports" => "Team",
|
||||
];
|
||||
}
|
||||
|
||||
class TeamSupporter extends DataObject {
|
||||
class TeamSupporter extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'Ranking' => 'Int',
|
||||
];
|
||||
@ -363,16 +365,16 @@ distinguish them like below:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Category extends DataObject {
|
||||
class Category extends DataObject
|
||||
{
|
||||
|
||||
private static $many_many = [
|
||||
'Products' => 'Product',
|
||||
'FeaturedProducts' => 'Product'
|
||||
];
|
||||
}
|
||||
|
||||
class Product extends DataObject {
|
||||
class Product extends DataObject
|
||||
{
|
||||
|
||||
private static $belongs_many_many = [
|
||||
'Categories' => 'Category.Products',
|
||||
@ -414,8 +416,8 @@ You can use the ORM to get a filtered result list without writing any SQL. For e
|
||||
See [DataObject::$has_many](api:SilverStripe\ORM\DataObject::$has_many) for more info on the described relations.
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $has_many = [
|
||||
"Players" => "Player"
|
||||
|
@ -14,8 +14,8 @@ In the `Player` example, we have four database columns each with a different dat
|
||||
**mysite/code/Player.php**
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'PlayerNumber' => 'Int',
|
||||
@ -53,8 +53,8 @@ For complex default values for newly instantiated objects see [Dynamic Default V
|
||||
For simple values you can make use of the `$defaults` array. For example:
|
||||
|
||||
```php
|
||||
|
||||
class Car extends DataObject {
|
||||
class Car extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Wheels' => 'Int',
|
||||
@ -84,8 +84,8 @@ For enum values, it's the second parameter.
|
||||
For example:
|
||||
|
||||
```php
|
||||
|
||||
class Car extends DataObject {
|
||||
class Car extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Wheels' => 'Int(4)',
|
||||
@ -107,8 +107,8 @@ object we can control the formatting and it allows us to call methods defined fr
|
||||
**mysite/code/Player.php**
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
..
|
||||
|
||||
@ -138,8 +138,8 @@ Then we can refer to a new `Name` column on our `Player` instances. In templates
|
||||
Rather than manually returning objects from your custom functions. You can use the `$casting` property.
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $casting = [
|
||||
"Name" => 'Varchar',
|
||||
@ -176,8 +176,8 @@ Most objects in SilverStripe extend from [ViewableData](api:SilverStripe\View\Vi
|
||||
context. Through a `$casting` array, arbitrary properties and getters can be casted:
|
||||
|
||||
```php
|
||||
|
||||
class MyObject extends ViewableData {
|
||||
class MyObject extends ViewableData
|
||||
{
|
||||
|
||||
private static $casting = [
|
||||
'MyDate' => 'Date'
|
||||
@ -215,8 +215,8 @@ The following example will use the result of `getStatus` instead of the 'Status'
|
||||
database column using `dbObject`.
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
"Status" => "Enum(array('Active', 'Injured', 'Retired'))"
|
||||
|
@ -19,8 +19,8 @@ a `ModelAdmin` record.
|
||||
Example: Disallow creation of new players if the currently logged-in player is not a team-manager.
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $has_many = [
|
||||
"Teams"=>"Team"
|
||||
@ -59,8 +59,8 @@ Example: Checking for a specific [permission](permissions) to delete this type o
|
||||
member is logged in who belongs to a group containing the permission "PLAYER_DELETE".
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $has_many = [
|
||||
"Teams" => "Team"
|
||||
|
@ -17,8 +17,8 @@ code.
|
||||
</div>
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
public function canView($member = null) {
|
||||
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
|
||||
|
@ -268,7 +268,8 @@ because of the custom SQL value transformation (`YEAR()`).
|
||||
An alternative approach would be a custom getter in the object definition.
|
||||
|
||||
```php
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'Birthdate' => 'Date'
|
||||
|
@ -22,8 +22,8 @@ write, and respond appropriately if it isn't.
|
||||
The return value of `validate()` is a [ValidationResult](api:SilverStripe\ORM\ValidationResult) object.
|
||||
|
||||
```php
|
||||
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Country' => 'Varchar',
|
||||
|
@ -21,7 +21,8 @@ also track versioned history.
|
||||
|
||||
|
||||
```php
|
||||
class MyStagedModel extends DataObject {
|
||||
class MyStagedModel extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class
|
||||
];
|
||||
@ -33,7 +34,8 @@ can be specified by setting the constructor argument to "Versioned"
|
||||
|
||||
|
||||
```php
|
||||
class VersionedModel extends DataObject {
|
||||
class VersionedModel extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
"SilverStripe\\ORM\\Versioning\\Versioned('Versioned')"
|
||||
];
|
||||
@ -184,7 +186,8 @@ without requiring any custom code.
|
||||
|
||||
|
||||
```php
|
||||
class MyPage extends Page {
|
||||
class MyPage extends Page
|
||||
{
|
||||
private static $has_many = [
|
||||
'Banners' => Banner::class
|
||||
];
|
||||
@ -192,8 +195,8 @@ without requiring any custom code.
|
||||
'Banners'
|
||||
];
|
||||
}
|
||||
|
||||
class Banner extends Page {
|
||||
class Banner extends Page
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class
|
||||
];
|
||||
@ -224,7 +227,8 @@ that can be used to traverse between each, and then by ensuring you configure bo
|
||||
E.g.
|
||||
|
||||
```php
|
||||
class MyParent extends DataObject {
|
||||
class MyParent extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class
|
||||
];
|
||||
@ -235,7 +239,8 @@ E.g.
|
||||
return MyChild::get();
|
||||
}
|
||||
}
|
||||
class MyChild extends DataObject {
|
||||
class MyChild extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class
|
||||
];
|
||||
@ -291,7 +296,8 @@ Versioned object visibility can be customised in one of the following ways by ed
|
||||
E.g.
|
||||
|
||||
```php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
@ -323,7 +329,8 @@ only be invoked if the object is in a non-published state.
|
||||
E.g.
|
||||
|
||||
```php
|
||||
class MyObjectExtension extends DataExtension {
|
||||
class MyObjectExtension extends DataExtension
|
||||
{
|
||||
public function canViewNonLive($member = null) {
|
||||
return Permission::check($member, 'DRAFT_STATUS');
|
||||
}
|
||||
@ -336,7 +343,8 @@ permissions in the `TargetObject.non_live_permissions` config.
|
||||
E.g.
|
||||
|
||||
```php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
|
@ -13,8 +13,8 @@ customise those fields as required.
|
||||
An example is `DataObject`, SilverStripe will automatically create your CMS interface so you can modify what you need.
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'IsActive' => 'Boolean',
|
||||
@ -60,8 +60,8 @@ The `$searchable_fields` property uses a mixed array format that can be used to
|
||||
system. The default is a set of array values listing the fields.
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name',
|
||||
@ -76,8 +76,8 @@ default search filter assigned (usually an [ExactMatchFilter](api:SilverStripe\O
|
||||
additional information on `$searchable_fields`:
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name' => 'PartialMatchFilter',
|
||||
@ -91,8 +91,8 @@ If you assign a single string value, you can set it to be either a [FormField](a
|
||||
both, you can assign an array:
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name' => [
|
||||
@ -112,8 +112,8 @@ both, you can assign an array:
|
||||
To include relations (`$has_one`, `$has_many` and `$many_many`) in your search, you can use a dot-notation.
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Varchar'
|
||||
@ -128,8 +128,8 @@ To include relations (`$has_one`, `$has_many` and `$many_many`) in your search,
|
||||
'Players.Name',
|
||||
];
|
||||
}
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
@ -149,8 +149,8 @@ Summary fields can be used to show a quick overview of the data for a specific [
|
||||
is their display as table columns, e.g. in the search results of a [ModelAdmin](api:SilverStripe\Admin\ModelAdmin) CMS interface.
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Text',
|
||||
@ -169,15 +169,15 @@ is their display as table columns, e.g. in the search results of a [ModelAdmin](
|
||||
To include relations or field manipulations in your summaries, you can use a dot-notation.
|
||||
|
||||
```php
|
||||
|
||||
class OtherObject extends DataObject {
|
||||
class OtherObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Varchar'
|
||||
];
|
||||
}
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Text',
|
||||
@ -200,8 +200,8 @@ To include relations or field manipulations in your summaries, you can use a dot
|
||||
Non-textual elements (such as images and their manipulations) can also be used in summaries.
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Text'
|
||||
|
@ -25,8 +25,8 @@ Indexes are represented on a `DataObject` through the `DataObject::$indexes` arr
|
||||
descriptor. There are several supported notations:
|
||||
|
||||
```php
|
||||
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
|
||||
private static $indexes = [
|
||||
'<column-name>' => true,
|
||||
@ -53,8 +53,8 @@ support the following:
|
||||
**mysite/code/MyTestObject.php**
|
||||
|
||||
```php
|
||||
|
||||
class MyTestObject extends DataObject {
|
||||
class MyTestObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'MyField' => 'Varchar',
|
||||
|
@ -48,8 +48,8 @@ provide default template for an object.
|
||||
|
||||
**mysite/code/Page.php**
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
public function forTemplate() {
|
||||
return "Page: ". $this->Title;
|
||||
@ -71,8 +71,8 @@ content that method sends back, or, provide a type in the `$casting` array for t
|
||||
to a template, SilverStripe will ensure that the object is wrapped in the correct type and values are safely escaped.
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
private static $casting = [
|
||||
'MyCustomMethod' => 'HTMLText'
|
||||
|
@ -9,8 +9,8 @@ subclass the base `Controller` class.
|
||||
**mysite/code/controllers/TeamController.php**
|
||||
|
||||
```php
|
||||
|
||||
class TeamController extends Controller {
|
||||
class TeamController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'players',
|
||||
|
@ -12,8 +12,8 @@ Any action you define on a controller must be defined in a `$allowed_actions` st
|
||||
directly calling methods that they shouldn't.
|
||||
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
// someaction can be accessed by anyone, any time
|
||||
@ -47,8 +47,8 @@ is specifically restricted.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
public function index() {
|
||||
// allowed without an $allowed_action defined
|
||||
@ -59,8 +59,8 @@ is specifically restricted.
|
||||
`$allowed_actions` can be defined on `Extension` classes applying to the controller.
|
||||
|
||||
```php
|
||||
|
||||
class MyExtension extends Extension {
|
||||
class MyExtension extends Extension
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'mycustomaction'
|
||||
@ -72,8 +72,8 @@ is specifically restricted.
|
||||
Only public methods can be made accessible.
|
||||
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'secure',
|
||||
@ -93,8 +93,8 @@ Only public methods can be made accessible.
|
||||
|
||||
If a method on a parent class is overwritten, access control for it has to be redefined as well.
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'action',
|
||||
@ -104,8 +104,8 @@ If a method on a parent class is overwritten, access control for it has to be re
|
||||
// ..
|
||||
}
|
||||
}
|
||||
|
||||
class MyChildController extends MyController {
|
||||
class MyChildController extends MyController
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'action', // required as we are redefining action
|
||||
@ -127,8 +127,8 @@ Access checks on parent classes need to be overwritten via the [Configuration AP
|
||||
Form action methods should **not** be included in `$allowed_actions`. However, the form method **should** be included
|
||||
as an `allowed_action`.
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'ContactForm' // use the Form method, not the action
|
||||
@ -151,8 +151,8 @@ Each method responding to a URL can also implement custom permission checks, e.g
|
||||
the passed request data.
|
||||
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'myaction'
|
||||
@ -184,8 +184,8 @@ execution. This behavior can be used to implement permission checks.
|
||||
`init` is called for any possible action on the controller and before any specific method such as `index`.
|
||||
</div>
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [];
|
||||
|
||||
|
@ -16,8 +16,8 @@ The following example will add a simple DateField to your Page, allowing you to
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'MyDate' => 'Date',
|
||||
|
@ -17,8 +17,8 @@ functionality. It is usually added through the [DataObject::getCMSFields()](api:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Content' => 'HTMLText'
|
||||
@ -46,7 +46,8 @@ This is particularly useful if you need different configurations for multiple [H
|
||||
|
||||
|
||||
```php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'Content' => 'HTMLText',
|
||||
'OtherContent' => 'HTMLText'
|
||||
@ -244,7 +245,8 @@ Example: Remove field for "image captions"
|
||||
|
||||
```php
|
||||
// File: mysite/code/MyToolbarExtension.php
|
||||
class MyToolbarExtension extends Extension {
|
||||
class MyToolbarExtension extends Extension
|
||||
{
|
||||
public function updateFieldsForImage(&$fields, $url, $file) {
|
||||
$fields->removeByName('CaptionText');
|
||||
}
|
||||
@ -284,7 +286,8 @@ of the CMS you have to take care of instantiate yourself:
|
||||
|
||||
```php
|
||||
// File: mysite/code/MyController.php
|
||||
class MyObjectController extends Controller {
|
||||
class MyObjectController extends Controller
|
||||
{
|
||||
public function Modals() {
|
||||
return ModalController::create($this, "Modals");
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ actions such as deleting records.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
@ -61,8 +61,8 @@ the `getConfig()` method on `GridField`.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
@ -269,8 +269,8 @@ The namespace notation is `ManyMany[<extradata-field-name>]`, so for example `Ma
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Team extends DataObject {
|
||||
class Team extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Text'
|
||||
@ -280,8 +280,8 @@ The namespace notation is `ManyMany[<extradata-field-name>]`, so for example `Ma
|
||||
'Players' => 'Player'
|
||||
];
|
||||
}
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Text'
|
||||
@ -352,8 +352,8 @@ create an area rendered before the table wrapped in a simple `<div>`.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAreaComponent implements GridField_HTMLProvider {
|
||||
class MyAreaComponent implements GridField_HTMLProvider
|
||||
{
|
||||
|
||||
public function getHTMLFragments( $gridField) {
|
||||
return [
|
||||
@ -374,8 +374,8 @@ Now you can add other components into this area by returning them as an array fr
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyShareLinkComponent implements GridField_HTMLProvider {
|
||||
class MyShareLinkComponent implements GridField_HTMLProvider
|
||||
{
|
||||
|
||||
public function getHTMLFragments( $gridField) {
|
||||
return [
|
||||
|
@ -11,8 +11,8 @@ code for a `Form` is to create it as a subclass to `Form`. Let's look at a examp
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
|
||||
public function SearchForm() {
|
||||
$fields = new FieldList(
|
||||
@ -69,8 +69,8 @@ should be. Good practice would be to move this to a subclass and create a new in
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class SearchForm extends Form {
|
||||
class SearchForm extends Form
|
||||
{
|
||||
|
||||
/**
|
||||
* Our constructor only requires the controller and the name of the form
|
||||
@ -131,8 +131,8 @@ Our controller will now just have to create a new instance of this form object.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'SearchForm',
|
||||
|
@ -19,8 +19,8 @@ below:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class GridFieldCustomAction implements GridField_ColumnProvider, GridField_ActionProvider {
|
||||
class GridFieldCustomAction implements GridField_ColumnProvider, GridField_ActionProvider
|
||||
{
|
||||
|
||||
public function augmentColumns($gridField, &$columns) {
|
||||
if(!in_array('Actions', $columns)) {
|
||||
|
@ -6,9 +6,11 @@ Let's start by defining a new `ContactPage` page type:
|
||||
|
||||
|
||||
```php
|
||||
class ContactPage extends Page {
|
||||
class ContactPage extends Page
|
||||
{
|
||||
}
|
||||
class ContactPageController extends PageController {
|
||||
class ContactPageController extends PageController
|
||||
{
|
||||
private static $allowed_actions = ['Form'];
|
||||
public function Form() {
|
||||
$fields = new FieldList(
|
||||
@ -70,7 +72,8 @@ Now that we have a contact form, we need some way of collecting the data submitt
|
||||
|
||||
|
||||
```php
|
||||
class ContactPageController extends PageController {
|
||||
class ContactPageController extends PageController
|
||||
{
|
||||
private static $allowed_actions = ['Form'];
|
||||
public function Form() {
|
||||
// ...
|
||||
|
@ -29,8 +29,8 @@ be marked `private static` and follow the `lower_case_with_underscores` structur
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyClass extends Page {
|
||||
class MyClass extends Page
|
||||
{
|
||||
|
||||
/**
|
||||
* @config
|
||||
|
@ -40,8 +40,8 @@ To extend the options available in the panel, define your own fields via a [Data
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class CustomSiteConfig extends DataExtension {
|
||||
class CustomSiteConfig extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'FooterContent' => 'HTMLText'
|
||||
|
@ -19,8 +19,8 @@ and `RequestHandler`. You can still apply extensions to descendants of these cla
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'DateOfBirth' => 'SS_Datetime'
|
||||
@ -79,8 +79,8 @@ $has_one etc.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Position' => 'Varchar',
|
||||
@ -158,8 +158,8 @@ validator by defining the `updateValidator` method.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
|
||||
// ..
|
||||
|
||||
@ -179,8 +179,8 @@ extension. The `CMS` provides a `updateCMSFields` Extension Hook to tie into.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Position' => 'Varchar',
|
||||
@ -225,8 +225,8 @@ In your [Extension](api:SilverStripe\Core\Extension) class you can only refer to
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
|
||||
public function updateFoo($foo) {
|
||||
// outputs the original class
|
||||
|
@ -50,8 +50,8 @@ First we need to define a callback for the shortcode.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
|
||||
private static $casting = [
|
||||
'MyShortCodeMethod' => 'HTMLText'
|
||||
|
@ -69,9 +69,8 @@ The `Injector` API can be used to define the types of `$dependencies` that an ob
|
||||
|
||||
|
||||
```php
|
||||
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
// both of these properties will be automatically
|
||||
// set by the injector on object creation
|
||||
@ -177,8 +176,8 @@ An example using the `MyFactory` service to create instances of the `MyService`
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyFactory implements SilverStripe\Core\Injector\Factory {
|
||||
class MyFactory implements SilverStripe\Core\Injector\Factory
|
||||
{
|
||||
|
||||
public function create($service, array $params = []) {
|
||||
return new MyServiceImplementation();
|
||||
@ -213,16 +212,16 @@ Assuming a class structure such as
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class RestrictivePermissionService {
|
||||
class RestrictivePermissionService
|
||||
{
|
||||
private $database;
|
||||
|
||||
public function setDatabase($d) {
|
||||
$this->database = $d;
|
||||
}
|
||||
}
|
||||
|
||||
class MySQLDatabase {
|
||||
class MySQLDatabase
|
||||
{
|
||||
private $username;
|
||||
private $password;
|
||||
|
||||
|
@ -47,8 +47,8 @@ used.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MySQLWriteDbAspect implements BeforeCallAspect {
|
||||
class MySQLWriteDbAspect implements BeforeCallAspect
|
||||
{
|
||||
|
||||
/**
|
||||
* @var MySQLDatabase
|
||||
|
@ -11,7 +11,8 @@ explicitly logging in or by invoking the "remember me" functionality.
|
||||
|
||||
|
||||
```php
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
private static $db = [
|
||||
'LastVisited' => 'Datetime',
|
||||
'NumVisit' => 'Int',
|
||||
|
@ -16,8 +16,8 @@ To include your fixture file in your tests, you should define it as your `$fixtu
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyNewTest extends SapphireTest {
|
||||
class MyNewTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = 'fixtures.yml';
|
||||
|
||||
@ -31,8 +31,8 @@ You can also use an array of fixture files, if you want to use parts of multiple
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyNewTest extends SapphireTest {
|
||||
class MyNewTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected static $fixture_file = [
|
||||
'fixtures.yml',
|
||||
|
@ -11,8 +11,8 @@ response and modify the session within a test.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class HomePageTest extends FunctionalTest {
|
||||
class HomePageTest extends FunctionalTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Test generation of the view
|
||||
|
@ -10,7 +10,8 @@ with information that we need.
|
||||
|
||||
|
||||
```php
|
||||
class MyObjectTest extends SapphireTest {
|
||||
class MyObjectTest extends SapphireTest
|
||||
{
|
||||
|
||||
protected $factory;
|
||||
|
||||
|
@ -49,7 +49,8 @@ You can define subclasses of [Member](api:SilverStripe\Security\Member) to add e
|
||||
|
||||
|
||||
```php
|
||||
class MyMember extends Member {
|
||||
class MyMember extends Member
|
||||
{
|
||||
private static $db = [
|
||||
"Age" => "Int",
|
||||
"Address" => "Text",
|
||||
@ -114,7 +115,8 @@ things, you should add appropriate [Permission::checkMember()](api:SilverStripe\
|
||||
|
||||
|
||||
```php
|
||||
class MyMemberExtension extends DataExtension {
|
||||
class MyMemberExtension extends DataExtension
|
||||
{
|
||||
/**
|
||||
|
||||
* Modify the field set to be displayed in the CMS detail pop-up
|
||||
|
@ -114,7 +114,8 @@ Example:
|
||||
|
||||
|
||||
```php
|
||||
class MyForm extends Form {
|
||||
class MyForm extends Form
|
||||
{
|
||||
public function save($RAW_data, $form) {
|
||||
// Pass true as the second parameter of raw2sql to quote the value safely
|
||||
$SQL_data = Convert::raw2sql($RAW_data, true); // works recursively on an array
|
||||
@ -132,7 +133,8 @@ Example:
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = ['myurlaction'];
|
||||
public function myurlaction($RAW_urlParams) {
|
||||
// Pass true as the second parameter of raw2sql to quote the value safely
|
||||
@ -150,7 +152,8 @@ passing data through, escaping should happen at the end of the chain.
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param array $RAW_data All names in an indexed array (not SQL-safe)
|
||||
*/
|
||||
@ -231,7 +234,8 @@ PHP:
|
||||
|
||||
|
||||
```php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'MyEscapedValue' => 'Text', // Example value: <b>not bold</b>
|
||||
'MyUnescapedValue' => 'HTMLText' // Example value: <b>bold</b>
|
||||
@ -280,7 +284,8 @@ PHP:
|
||||
|
||||
|
||||
```php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
public $Title = '<b>not bold</b>'; // will be escaped due to Text casting
|
||||
|
||||
$casting = [
|
||||
@ -322,7 +327,8 @@ PHP:
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = ['search'];
|
||||
public function search($request) {
|
||||
$htmlTitle = '<p>Your results for:' . Convert::raw2xml($request->getVar('Query')) . '</p>';
|
||||
@ -355,7 +361,8 @@ PHP:
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = ['search'];
|
||||
public function search($request) {
|
||||
$rssRelativeLink = "/rss?Query=" . urlencode($_REQUEST['query']) . "&sortOrder=asc";
|
||||
@ -548,7 +555,8 @@ controller's `init()` method:
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
public function init() {
|
||||
parent::init();
|
||||
$this->getResponse()->addHeader('X-Frame-Options', 'SAMEORIGIN');
|
||||
@ -687,7 +695,8 @@ and `Date: <current date>` will ensure that sensitive content is not stored loca
|
||||
unauthorised local persons. SilverStripe adds the current date for every request, and we can add the other cache
|
||||
headers to the request for our secure controllers:
|
||||
```php
|
||||
class MySecureController extends Controller {
|
||||
class MySecureController extends Controller
|
||||
{
|
||||
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
@ -49,7 +49,8 @@ The simplest way to use [CsvBulkLoader](api:SilverStripe\Dev\CsvBulkLoader) is t
|
||||
|
||||
|
||||
```php
|
||||
class PlayerAdmin extends ModelAdmin {
|
||||
class PlayerAdmin extends ModelAdmin
|
||||
{
|
||||
private static $managed_models = [
|
||||
'Player'
|
||||
];
|
||||
@ -74,7 +75,8 @@ You'll need to add a route to your controller to make it accessible via URL
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = ['Form'];
|
||||
|
||||
@ -134,7 +136,8 @@ Datamodel for Player
|
||||
|
||||
|
||||
```php
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'PlayerNumber' => 'Int',
|
||||
'FirstName' => 'Text',
|
||||
@ -153,7 +156,8 @@ Datamodel for FootballTeam:
|
||||
|
||||
|
||||
```php
|
||||
class FootballTeam extends DataObject {
|
||||
class FootballTeam extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'Title' => 'Text',
|
||||
];
|
||||
@ -172,7 +176,8 @@ Sample implementation of a custom loader. Assumes a CSV-file in a certain format
|
||||
* Avoids duplicate imports by a custom `$duplicateChecks` definition
|
||||
* Creates `Team` relations automatically based on the `Gruppe` column in the CSV data
|
||||
```php
|
||||
class PlayerCsvBulkLoader extends CsvBulkLoader {
|
||||
class PlayerCsvBulkLoader extends CsvBulkLoader
|
||||
{
|
||||
public $columnMap = [
|
||||
'Number' => 'PlayerNumber',
|
||||
'Name' => '->importFirstAndLastName',
|
||||
@ -206,7 +211,8 @@ Building off of the ModelAdmin example up top, use a custom loader instead of th
|
||||
|
||||
|
||||
```php
|
||||
class PlayerAdmin extends ModelAdmin {
|
||||
class PlayerAdmin extends ModelAdmin
|
||||
{
|
||||
private static $managed_models = [
|
||||
'Player'
|
||||
];
|
||||
|
@ -160,8 +160,8 @@ If the web service returned an error (for example, API key not available or inad
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyRestfulService extends RestfulService {
|
||||
class MyRestfulService extends RestfulService
|
||||
{
|
||||
|
||||
public function errorCatch($response) {
|
||||
$err_msg = $response;
|
||||
@ -179,8 +179,8 @@ If you want to bypass error handling, define `checkErrors` in the constructor fo
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyRestfulService extends RestfulService {
|
||||
class MyRestfulService extends RestfulService
|
||||
{
|
||||
|
||||
public function __construct($expiry = NULL) {
|
||||
parent::__construct('http://www.flickr.com/services/rest/', $expiry);
|
||||
|
@ -58,8 +58,8 @@ You can use [RSSFeed](api:SilverStripe\Control\RSS\RSSFeed) to easily create a f
|
||||
```php
|
||||
|
||||
..
|
||||
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'rss'
|
||||
@ -103,8 +103,8 @@ method is defined and returns a string to the full website URL.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
public function AbsoluteLink() {
|
||||
// assumes players can be accessed at yoursite.com/players/2
|
||||
@ -122,8 +122,8 @@ Then in our controller, we add a new action which returns a the XML list of `Pla
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'players'
|
||||
|
@ -8,8 +8,8 @@ form (which is used for `MyDataObject` instances). You can access it through
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'Form'
|
||||
|
@ -17,8 +17,8 @@ information about the individual player and a relation set up for managing the `
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Player extends DataObject {
|
||||
class Player extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'PlayerNumber' => 'Int',
|
||||
@ -38,8 +38,8 @@ information about the individual player and a relation set up for managing the `
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class FootballTeam extends DataObject {
|
||||
class FootballTeam extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Text'
|
||||
@ -68,8 +68,8 @@ Our final import looks like this.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class PlayerCsvBulkLoader extends CsvBulkLoader {
|
||||
class PlayerCsvBulkLoader extends CsvBulkLoader
|
||||
{
|
||||
|
||||
public $columnMap = [
|
||||
'Number' => 'PlayerNumber',
|
||||
|
@ -20,8 +20,8 @@ Defining search-able fields on your DataObject.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name',
|
||||
@ -39,8 +39,8 @@ and `MyDate`. The attribute `HiddenProperty` should not be searchable, and `MyDa
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'PublicProperty' => 'Text'
|
||||
@ -84,8 +84,8 @@ the `$fields` constructor parameter.
|
||||
```php
|
||||
|
||||
// ..
|
||||
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
|
||||
public function SearchForm() {
|
||||
$context = singleton('MyDataObject')->getCustomSearchContext();
|
||||
|
@ -23,8 +23,8 @@ You can do so by adding this static variable to your class definition:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyDataObject extends DataObject {
|
||||
class MyDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $create_table_options = [
|
||||
'MySQLDatabase' => 'ENGINE=MyISAM'
|
||||
@ -50,7 +50,8 @@ Example DataObject:
|
||||
|
||||
|
||||
```php
|
||||
class SearchableDataObject extends DataObject {
|
||||
class SearchableDataObject extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
"Title" => "Varchar(255)",
|
||||
|
@ -53,7 +53,8 @@ within the assets folder).
|
||||
For example, to load a temporary file into a DataObject you could use the below:
|
||||
```php
|
||||
<?
|
||||
class Banner extends DataObject {
|
||||
class Banner extends DataObject
|
||||
{
|
||||
private static $db = [
|
||||
'Image' => 'DBFile'
|
||||
];
|
||||
|
@ -65,7 +65,8 @@ authorised users, the following should be considered:
|
||||
|
||||
|
||||
```php
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
public function init() {
|
||||
parent::init();
|
||||
// Whitelist any protected files on this page for the current user
|
||||
@ -96,7 +97,8 @@ authorised users, the following should be considered:
|
||||
|
||||
|
||||
```php
|
||||
class PageController extends ContentController {
|
||||
class PageController extends ContentController
|
||||
{
|
||||
public function init() {
|
||||
parent::init();
|
||||
// Whitelist any protected files on this page for the current user
|
||||
@ -309,7 +311,8 @@ the `Versioned` extension.
|
||||
|
||||
|
||||
```php
|
||||
class MyVersiondObject extends DataObject {
|
||||
class MyVersiondObject extends DataObject
|
||||
{
|
||||
/** Ensure assets are archived along with the DataObject */
|
||||
private static $keep_archived_assets = true;
|
||||
/** Versioned */
|
||||
|
@ -21,8 +21,8 @@ a category.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Product extends DataObject {
|
||||
class Product extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
@ -41,8 +41,8 @@ a category.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Category extends DataObject {
|
||||
class Category extends DataObject
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'Title' => 'Text'
|
||||
@ -64,8 +64,8 @@ We'll name it `MyAdmin`, but the class name can be anything you want.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
private static $managed_models = [
|
||||
'Product',
|
||||
@ -104,8 +104,8 @@ permissions by default. For most cases, less restrictive checks make sense, e.g.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Category extends DataObject {
|
||||
class Category extends DataObject
|
||||
{
|
||||
// ...
|
||||
public function canView($member = null) {
|
||||
return Permission::check('CMS_ACCESS_MyAdmin', 'any', $member);
|
||||
@ -138,8 +138,8 @@ class (see [SearchContext](../search/searchcontext) docs for details).
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Product extends DataObject {
|
||||
class Product extends DataObject
|
||||
{
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name',
|
||||
@ -163,8 +163,8 @@ model class, where you can add or remove columns. To change the title, use [Data
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class Product extends DataObject {
|
||||
class Product extends DataObject
|
||||
{
|
||||
|
||||
private static $field_labels = [
|
||||
'Price' => 'Cost' // renames the column to "Cost"
|
||||
@ -188,8 +188,8 @@ For example, we might want to exclude all products without prices in our sample
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
public function getList() {
|
||||
$list = parent::getList();
|
||||
@ -211,8 +211,8 @@ checkbox which limits search results to expensive products (over $100).
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
public function getSearchContext() {
|
||||
$context = parent::getSearchContext();
|
||||
@ -245,8 +245,8 @@ example, to add a new component.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
private static $managed_models = [
|
||||
'Product',
|
||||
@ -279,8 +279,8 @@ to only one specific `GridField`:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
private static $managed_models = [
|
||||
'Product',
|
||||
@ -321,8 +321,8 @@ To customize the exported columns, create a new method called `getExportFields`
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyAdmin extends ModelAdmin {
|
||||
class MyAdmin extends ModelAdmin
|
||||
{
|
||||
// ...
|
||||
|
||||
public function getExportFields() {
|
||||
|
@ -162,7 +162,8 @@ Basic example form in a CMS controller subclass:
|
||||
|
||||
|
||||
```php
|
||||
class MyAdmin extends LeftAndMain {
|
||||
class MyAdmin extends LeftAndMain
|
||||
{
|
||||
function getEditForm() {
|
||||
return CMSForm::create(
|
||||
$this,
|
||||
@ -362,7 +363,8 @@ in a single Ajax request.
|
||||
|
||||
```php
|
||||
// mysite/code/MyAdmin.php
|
||||
class MyAdmin extends LeftAndMain {
|
||||
class MyAdmin extends LeftAndMain
|
||||
{
|
||||
private static $url_segment = 'myadmin';
|
||||
public function getResponseNegotiator() {
|
||||
$negotiator = parent::getResponseNegotiator();
|
||||
@ -486,8 +488,10 @@ without affecting the response body.
|
||||
|
||||
|
||||
```php
|
||||
class MyController extends LeftAndMain {
|
||||
class myaction() {
|
||||
class MyController extends LeftAndMain
|
||||
{
|
||||
class myaction()
|
||||
{
|
||||
// ...
|
||||
$this->getResponse()->addHeader('X-Controller', 'MyOtherController');
|
||||
return $html;
|
||||
|
@ -421,7 +421,8 @@ PHP:
|
||||
|
||||
|
||||
```php
|
||||
class MyController {
|
||||
class MyController
|
||||
{
|
||||
public function autocomplete($request) {
|
||||
$results = Page::get()->filter("Title", $request->getVar('title'));
|
||||
if(!$results) return new HTTPResponse("Not found", 404);
|
||||
|
@ -450,7 +450,9 @@ __my-module/js/components/Gallery.js__
|
||||
import React from 'react';
|
||||
import { inject } from 'lib/Injector';
|
||||
|
||||
class Gallery extends React.Component {
|
||||
class Gallery extends React.Component
|
||||
|
||||
{
|
||||
render() {
|
||||
const { SearchComponent, ItemComponent } = this.props;
|
||||
return (
|
||||
@ -482,7 +484,8 @@ declare them in `inject()`. In cases like this, use `withInjector()`. This highe
|
||||
component puts the `Injector` instance in `context`.
|
||||
|
||||
```js
|
||||
class MyGallery extends React.Component {
|
||||
class MyGallery extends React.Component
|
||||
{
|
||||
render () {
|
||||
<div>
|
||||
{this.props.items.map(item => {
|
||||
|
@ -22,7 +22,8 @@ black-and-transparent PNG graphics. In this case we'll place the icon in
|
||||
|
||||
|
||||
```php
|
||||
class ProductAdmin extends ModelAdmin {
|
||||
class ProductAdmin extends ModelAdmin
|
||||
{
|
||||
// ...
|
||||
private static $menu_icon = 'mysite/images/product-icon.png';
|
||||
}
|
||||
@ -36,7 +37,8 @@ controller, removing the "Admin" bit at the end.
|
||||
|
||||
|
||||
```php
|
||||
class ProductAdmin extends ModelAdmin {
|
||||
class ProductAdmin extends ModelAdmin
|
||||
{
|
||||
// ...
|
||||
private static $menu_title = 'My Custom Admin';
|
||||
}
|
||||
@ -60,8 +62,8 @@ button configuration.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class CustomLeftAndMain extends LeftAndMainExtension {
|
||||
class CustomLeftAndMain extends LeftAndMainExtension
|
||||
{
|
||||
|
||||
public function init() {
|
||||
// unique identifier for this item. Will have an ID of Menu-$ID
|
||||
|
@ -20,12 +20,14 @@ hypothetical `NewsPageHolder` type, which contains `NewsPage` children.
|
||||
|
||||
```php
|
||||
// mysite/code/NewsPageHolder.php
|
||||
class NewsPageHolder extends Page {
|
||||
class NewsPageHolder extends Page
|
||||
{
|
||||
private static $allowed_children = ['NewsPage'];
|
||||
}
|
||||
|
||||
// mysite/code/NewsPage.php
|
||||
class NewsPage extends Page {
|
||||
class NewsPage extends Page
|
||||
{
|
||||
private static $has_one = [
|
||||
'Author' => 'Member',
|
||||
];
|
||||
@ -42,7 +44,8 @@ or across page types with common characteristics.
|
||||
|
||||
```php
|
||||
// mysite/code/NewsPageHolderCMSMainExtension.php
|
||||
class NewsPageHolderCMSMainExtension extends Extension {
|
||||
class NewsPageHolderCMSMainExtension extends Extension
|
||||
{
|
||||
function updateListView($listView) {
|
||||
$parentId = $listView->getController()->getRequest()->requestVar('ParentID');
|
||||
$parent = ($parentId) ? Page::get()->byId($parentId) : new Page();
|
||||
|
@ -66,7 +66,8 @@ __Example: using a subclass__
|
||||
|
||||
|
||||
```php
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
public function getScheduledToPublish(){
|
||||
// return either true or false
|
||||
}
|
||||
|
@ -161,7 +161,8 @@ _my-module/js/src/ConfirmingFormAction.js_
|
||||
import React from 'react';
|
||||
|
||||
export default (FormAction) => {
|
||||
class ConfirmingFormAction extends React.Component {
|
||||
class ConfirmingFormAction extends React.Component
|
||||
{
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { confirming: false };
|
||||
|
@ -34,7 +34,8 @@ The following example will create a report to list every page on the current sit
|
||||
|
||||
###CustomSideReport.php
|
||||
```php
|
||||
class CustomSideReport_NameOfReport extends SS_Report {
|
||||
class CustomSideReport_NameOfReport extends SS_Report
|
||||
{
|
||||
|
||||
// the name of the report
|
||||
public function title() {
|
||||
|
@ -80,8 +80,8 @@ and insert the following code.
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class BookmarkedPageExtension extends DataExtension {
|
||||
class BookmarkedPageExtension extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = [
|
||||
'IsBookmarked' => 'Boolean'
|
||||
@ -120,8 +120,8 @@ Add the following code to a new file `mysite/code/BookmarkedLeftAndMainExtension
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class BookmarkedPagesLeftAndMainExtension extends LeftAndMainExtension {
|
||||
class BookmarkedPagesLeftAndMainExtension extends LeftAndMainExtension
|
||||
{
|
||||
|
||||
public function BookmarkedPages() {
|
||||
return Page::get()->filter("IsBookmarked", 1);
|
||||
@ -236,7 +236,8 @@ applicable controller actions to it:
|
||||
|
||||
|
||||
```php
|
||||
class CustomActionsExtension extends LeftAndMainExtension {
|
||||
class CustomActionsExtension extends LeftAndMainExtension
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'sampleAction'
|
||||
|
@ -5,7 +5,8 @@ also another tool at your disposal: The [Extension](api:SilverStripe\Core\Extens
|
||||
|
||||
|
||||
```php
|
||||
class MyAdminExtension extends Extension {
|
||||
class MyAdminExtension extends Extension
|
||||
{
|
||||
// ...
|
||||
public function updateEditForm(&$form) {
|
||||
$form->Fields()->push(/* ... */)
|
||||
|
@ -20,7 +20,8 @@ This example uses [Cache](api:Cache) in some custom code, and the same cache is
|
||||
|
||||
|
||||
```php
|
||||
class MyClass extends DataObject implements Flushable {
|
||||
class MyClass extends DataObject implements Flushable
|
||||
{
|
||||
|
||||
public static function flush() {
|
||||
Cache::factory('mycache')->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||
@ -46,7 +47,8 @@ useful in an example like `GD` or `Imagick` generating resampled images, but we
|
||||
flush so they are re-created on demand.
|
||||
|
||||
```php
|
||||
class MyClass extends DataObject implements Flushable {
|
||||
class MyClass extends DataObject implements Flushable
|
||||
{
|
||||
|
||||
public static function flush() {
|
||||
foreach(glob(ASSETS_PATH . '/_tempfiles/*.jpg') as $file) {
|
||||
|
@ -93,8 +93,8 @@ This code provides a good template:
|
||||
|
||||
|
||||
```php
|
||||
|
||||
class MyProcess extends Controller {
|
||||
class MyProcess extends Controller
|
||||
{
|
||||
|
||||
private static $allowed_actions = [
|
||||
'index'
|
||||
|
@ -74,7 +74,8 @@ Because of this, you will need to change the static definitions in your ModelAdm
|
||||
change this:
|
||||
|
||||
:::php
|
||||
class MyCatalogAdmin extends ModelAdmin {
|
||||
class MyCatalogAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
protected static $managed_models = array(
|
||||
'Product',
|
||||
@ -88,7 +89,8 @@ change this:
|
||||
To this:
|
||||
|
||||
:::php
|
||||
class MyCatalogAdmin extends ModelAdmin {
|
||||
class MyCatalogAdmin extends ModelAdmin
|
||||
{
|
||||
|
||||
public static $managed_models = array(
|
||||
'Product',
|
||||
|
@ -188,7 +188,8 @@ getter. You need to manually call *setOwner($this)* before using the instance.
|
||||
Base setup:
|
||||
|
||||
:::php
|
||||
class MyExtension extends Extension {
|
||||
class MyExtension extends Extension
|
||||
{
|
||||
function myExtensionMethod() { // ... }
|
||||
}
|
||||
Object::add_extension('MyObject', 'MyExtension');
|
||||
@ -197,7 +198,8 @@ Base setup:
|
||||
Wrong:
|
||||
|
||||
:::php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
function myExtensionMethod() {
|
||||
$ext = $this->extension_instances['MyExtension'];
|
||||
return $ext->myExtensionMethod();
|
||||
@ -208,7 +210,8 @@ Wrong:
|
||||
Right:
|
||||
|
||||
:::php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
function myExtensionMethod() {
|
||||
$ext = $this->getExtensionInstance('MyExtension');
|
||||
$ext->setOwner($this);
|
||||
|
@ -127,7 +127,8 @@ To clarify: Leaving existing decorators unchanged might mean that you allow acti
|
||||
|
||||
// 2.4.0
|
||||
:::php
|
||||
class MyDecorator extends DataObjectDecorator {
|
||||
class MyDecorator extends DataObjectDecorator
|
||||
{
|
||||
function canEdit($member) {
|
||||
if(Permission::checkMember($member, 'MYPERMISSION')) {
|
||||
return true;
|
||||
@ -139,7 +140,8 @@ To clarify: Leaving existing decorators unchanged might mean that you allow acti
|
||||
|
||||
// 2.4.1
|
||||
:::php
|
||||
class MyDecorator extends DataObjectDecorator {
|
||||
class MyDecorator extends DataObjectDecorator
|
||||
{
|
||||
function canEdit($member) {
|
||||
if(Permission::checkMember($member, 'MYPERMISSION')) {
|
||||
return null; // Means the permission check will be ignored, instead of forced to TRUE
|
||||
|
@ -48,7 +48,8 @@ parameters (//$data, $form// instead of *$request*).
|
||||
|
||||
:::php
|
||||
// Form field actions
|
||||
class MyFormField extends FormField {
|
||||
class MyFormField extends FormField
|
||||
{
|
||||
|
||||
// Form fields always have a reference to their form.
|
||||
// Use the form-specific token instance.
|
||||
@ -61,7 +62,8 @@ parameters (//$data, $form// instead of *$request*).
|
||||
}
|
||||
|
||||
// Controller actions (GET and POST) without form
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
// Manually adds token to link
|
||||
function DeleteLink() {
|
||||
@ -84,7 +86,8 @@ parameters (//$data, $form// instead of *$request*).
|
||||
}
|
||||
|
||||
// Controller actions (GET and POST) with form
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
// Forms have CSRF protection turned on by default,
|
||||
// will add a HiddenField instance called "SecurityID"
|
||||
@ -160,7 +163,8 @@ parameters don't break through string concatenation.
|
||||
Full controller example:
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
|
||||
function export($request) {
|
||||
// ...
|
||||
@ -189,7 +193,8 @@ mandatory "SecurityID" GET parameter appended to the base link.
|
||||
You can manually enable security tokens, either globally or for a specific form.
|
||||
|
||||
:::php
|
||||
class MyTest extends SapphireTest {
|
||||
class MyTest extends SapphireTest
|
||||
{
|
||||
|
||||
// option 1: enable for all forms created through this test
|
||||
function setUp() {
|
||||
|
@ -143,7 +143,8 @@ If you need custom logic, e.g. checking for a class before applying the statics
|
||||
you can use `add_to_class()` as a replacement to `extraStatics()`.
|
||||
|
||||
:::php
|
||||
class MyExtension extends Extension {
|
||||
class MyExtension extends Extension
|
||||
{
|
||||
|
||||
// before
|
||||
function extraStatics($class, $extensionClass) {
|
||||
|
@ -21,7 +21,8 @@ and doesn't check if the user is authenticated to view it. As with any other con
|
||||
please use `DataObject->canView()` to determine permissions.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = array('showpage');
|
||||
public function showpage($request) {
|
||||
$page = Page::get()->byID($request->param('ID'));
|
||||
|
@ -75,10 +75,12 @@ Before:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
static $db = array('MyVar' => 'Text');
|
||||
}
|
||||
class Page_Controller extends ContentController {
|
||||
class Page_Controller extends ContentController
|
||||
{
|
||||
static $allowed_actions = array('myaction');
|
||||
}
|
||||
|
||||
@ -86,10 +88,12 @@ After:
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
private static $db = array('MyVar' => 'Text');
|
||||
}
|
||||
class Page_Controller extends ContentController {
|
||||
class Page_Controller extends ContentController
|
||||
{
|
||||
private static $allowed_actions = array('myaction');
|
||||
}
|
||||
|
||||
@ -116,7 +120,8 @@ as such. This can either be done by returning an HTMLText object, like:
|
||||
or by defining the casting of the accessor method, like:
|
||||
|
||||
:::php
|
||||
class Page extends SiteTree {
|
||||
class Page extends SiteTree
|
||||
{
|
||||
private static $casting = array(
|
||||
'MyDiv' => 'HTMLText'
|
||||
)
|
||||
@ -242,7 +247,8 @@ understand, the routing will require definition of `$allowed_actions`
|
||||
on your own `Controller` subclasses if they contain any actions accessible through URLs.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
// This action is now denied because no $allowed_actions are specified
|
||||
public function myaction($request) {}
|
||||
}
|
||||
@ -263,7 +269,8 @@ particularly around inherited rules. We've decided to remove the feature,
|
||||
you'll need to specificy each accessible action individually.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
public static $allowed_actions = array('*' => 'ADMIN');
|
||||
// Always denied because not explicitly listed in $allowed_actions
|
||||
public function myaction($request) {}
|
||||
@ -281,11 +288,13 @@ to methods defined on the class they're also defined on.
|
||||
Overriding inherited access definitions is no longer possible.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
public static $allowed_actions = array('myaction' => 'ADMIN');
|
||||
public function myaction($request) {}
|
||||
}
|
||||
class MySubController extends MyController {
|
||||
class MySubController extends MyController
|
||||
{
|
||||
// No longer works
|
||||
public static $allowed_actions = array('myaction' => 'CMS_ACCESS_CMSMAIN');
|
||||
}
|
||||
@ -298,7 +307,8 @@ can only grant or deny access or methods they define themselves.
|
||||
New approach with the [Config API](/developer_guides/configuration/configuration)
|
||||
|
||||
:::php
|
||||
class MySubController extends MyController {
|
||||
class MySubController extends MyController
|
||||
{
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
@ -321,7 +331,8 @@ If you have previously added, removed or altered built-in CMS actions in any way
|
||||
you'll need to adjust your code.
|
||||
|
||||
:::php
|
||||
class MyPage extends Page {
|
||||
class MyPage extends Page
|
||||
{
|
||||
function getCMSActions() {
|
||||
$actions = parent::getCMSActions();
|
||||
|
||||
@ -363,7 +374,8 @@ Since `GridField` is used in `ModelAdmin`, this change will affect both classes.
|
||||
Example: Require "CMS: Pages section" access
|
||||
|
||||
:::php
|
||||
class MyModel extends DataObject {
|
||||
class MyModel extends DataObject
|
||||
{
|
||||
public function canView($member = null) {
|
||||
return Permission::check('CMS_ACCESS_CMSMain', 'any', $member);
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ E.g.
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class SingletonPage extends Page {
|
||||
class SingletonPage extends Page
|
||||
{
|
||||
public function canCreate($member) {
|
||||
if(static::get()->count()) return false;
|
||||
|
||||
|
@ -13,7 +13,8 @@ For example:
|
||||
|
||||
|
||||
:::php
|
||||
class MyCustomValidator extends Validator {
|
||||
class MyCustomValidator extends Validator
|
||||
{
|
||||
public function php($data) {
|
||||
$this->validationError(
|
||||
'EmailAddress',
|
||||
|
@ -8,7 +8,8 @@ login forms or other changes. To re-enable this, you'll need to use the `Injecto
|
||||
Define a login form:
|
||||
|
||||
```php
|
||||
class CustomLoginForm extends MemberLoginForm {
|
||||
class CustomLoginForm extends MemberLoginForm
|
||||
{
|
||||
|
||||
public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
|
||||
{
|
||||
|
@ -31,7 +31,8 @@ and doesn't check if the user is authenticated to view it. As with any other con
|
||||
please use `DataObject->canView()` to determine permissions.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = array('showpage');
|
||||
public function showpage($request) {
|
||||
$page = Page::get()->byID($request->param('ID'));
|
||||
|
@ -15,7 +15,8 @@ E.g.
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class FileSecurityExtension extends DataExtension {
|
||||
class FileSecurityExtension extends DataExtension
|
||||
{
|
||||
public function canEdit($member) {
|
||||
return Permission::checkMember($member, 'MyCustomPermission');
|
||||
}
|
||||
|
@ -308,7 +308,8 @@ simply use the provided page URLs.
|
||||
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
static $allowed_actions = array('myaction');
|
||||
public function myaction($request) {
|
||||
// ...
|
||||
|
@ -13,7 +13,8 @@ For example:
|
||||
|
||||
|
||||
:::php
|
||||
class MyCustomValidator extends Validator {
|
||||
class MyCustomValidator extends Validator
|
||||
{
|
||||
public function php($data) {
|
||||
$this->validationError(
|
||||
'EmailAddress',
|
||||
|
@ -8,7 +8,8 @@ login forms or other changes. To re-enable this, you'll need to use the `Injecto
|
||||
Define a login form:
|
||||
|
||||
```php
|
||||
class CustomLoginForm extends MemberLoginForm {
|
||||
class CustomLoginForm extends MemberLoginForm
|
||||
{
|
||||
|
||||
public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
|
||||
{
|
||||
|
@ -8,7 +8,8 @@ login forms or other changes. To re-enable this, you'll need to use the `Injecto
|
||||
Define a login form:
|
||||
|
||||
```php
|
||||
class CustomLoginForm extends MemberLoginForm {
|
||||
class CustomLoginForm extends MemberLoginForm
|
||||
{
|
||||
|
||||
public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
|
||||
{
|
||||
|
@ -994,7 +994,9 @@ Before this change, to use the handle_shortcode method, you would do something l
|
||||
```
|
||||
<?php
|
||||
|
||||
class MyShortcodeUser extends Object {
|
||||
class MyShortcodeUser extends Object
|
||||
|
||||
{
|
||||
|
||||
|
||||
private $content;
|
||||
@ -1012,7 +1014,9 @@ In the new situation, this would look like this:
|
||||
|
||||
use SilverStripe\Assets\Shortcodes\FileShortcodeProvider;
|
||||
|
||||
class MyShortcodeUser extends Object {
|
||||
class MyShortcodeUser extends Object
|
||||
|
||||
{
|
||||
|
||||
private $content;
|
||||
|
||||
|
@ -369,7 +369,8 @@ E.g.
|
||||
|
||||
|
||||
:::php
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $has_one = array(
|
||||
"ImageObject" => "Image"
|
||||
);
|
||||
@ -451,7 +452,8 @@ Before:
|
||||
|
||||
:::php
|
||||
// in MyImageExtension.php
|
||||
class MyImageExtension extends DataExtension {
|
||||
class MyImageExtension extends DataExtension
|
||||
{
|
||||
public function GalleryThumbnail($height) {
|
||||
return $this->getFormattedImage('GalleryThumbnail', $height);
|
||||
}
|
||||
@ -471,7 +473,8 @@ After:
|
||||
|
||||
:::php
|
||||
// in MyImageExtension.php
|
||||
class MyImageExtension extends Extension {
|
||||
class MyImageExtension extends Extension
|
||||
{
|
||||
public function GalleryThumbnail($height) {
|
||||
// Generates the manipulation key
|
||||
$variant = $this->owner->variantName(__FUNCTION__, $height);
|
||||
@ -509,7 +512,8 @@ The below describes the minimum amount of effort required to implement a composi
|
||||
|
||||
:::php
|
||||
<?
|
||||
class MyAddressField extends DBComposite {
|
||||
class MyAddressField extends DBComposite
|
||||
{
|
||||
|
||||
private static $composite_db = array(
|
||||
'Street' => 'Varchar(200)',
|
||||
@ -607,7 +611,8 @@ E.g.
|
||||
|
||||
|
||||
:::php
|
||||
class MyErrorPageExtension extends SiteTreeExtension {
|
||||
class MyErrorPageExtension extends SiteTreeExtension
|
||||
{
|
||||
public function updateErrorFilename(&$name, &$statuscode) {
|
||||
if($this->owner->exists()) {
|
||||
$locale = $this->Locale;
|
||||
@ -721,7 +726,8 @@ For instance:
|
||||
/**
|
||||
* This model has staging and versioning. Stages will be "Stage" and "Live"
|
||||
*/
|
||||
class MyStagedModel extends DataObject {
|
||||
class MyStagedModel extends DataObject
|
||||
{
|
||||
private staic $extensions = array(
|
||||
"Versioned('StagedVersioned')"
|
||||
);
|
||||
@ -730,7 +736,8 @@ For instance:
|
||||
/**
|
||||
* This model has versioning only, and will not has a draft or live stage, nor be affected by the current stage.
|
||||
*/
|
||||
class MyVersionedModel extends DataObject {
|
||||
class MyVersionedModel extends DataObject
|
||||
{
|
||||
private static $extensions = array(
|
||||
"Versioned('Versioned')"
|
||||
);
|
||||
@ -783,8 +790,8 @@ This means that for the most part, code that worked in 3.0 won't need to be chan
|
||||
An exception to this is any classes which once had the `SS_` prefix, which will now be instead prefixed with `DB`, and have an un-aliased prefix. For example `SS_Datetime` is now `DBDateTime`, and has the alias `DateTime` which may be used in config.
|
||||
|
||||
For example:
|
||||
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $db = array(
|
||||
'Number' => 'Int',
|
||||
'Time' => 'SS_Datetime'
|
||||
@ -802,8 +809,8 @@ For example:
|
||||
Will become:
|
||||
|
||||
use SilverStripe\Model\FieldType\DBVarchar;
|
||||
|
||||
class MyObject extends DataObject {
|
||||
class MyObject extends DataObject
|
||||
{
|
||||
private static $db = array(
|
||||
'Number' => 'Int',
|
||||
'Time' => 'Datetime'
|
||||
|
@ -276,7 +276,8 @@ simply use the provided page URLs.
|
||||
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
static $allowed_actions = array('myaction');
|
||||
public function myaction($request) {
|
||||
// ...
|
||||
|
@ -31,7 +31,8 @@ and doesn't check if the user is authenticated to view it. As with any other con
|
||||
please use `DataObject->canView()` to determine permissions.
|
||||
|
||||
:::php
|
||||
class MyController extends Controller {
|
||||
class MyController extends Controller
|
||||
{
|
||||
private static $allowed_actions = array('showpage');
|
||||
public function showpage($request) {
|
||||
$page = Page::get()->byID($request->param('ID'));
|
||||
|
Loading…
Reference in New Issue
Block a user