Fixed _config.php references and usage in docs

This commit is contained in:
Ingo Schommer 2013-03-27 12:06:57 +01:00
parent 8dbdb00400
commit 315c03872a
16 changed files with 77 additions and 60 deletions

View File

@ -62,7 +62,11 @@ or across page types with common characteristics.
}
}
Now you just need to enable the extension in your [configuration file](/topics/configuration).
// mysite/_config/config.yml
LeftAndMain:
extensions:
- NewsPageHolderCMSMainExtension
- NewsPageHolderCMSMainExtension
You're all set! Don't forget to flush the caches by appending `?flush=all` to the URL.

View File

@ -82,10 +82,12 @@ Create a new file called `mysite/code/BookmarkedPageExtension.php` and insert th
}
}
Enable the extension with the following line in `mysite/_config.php`:
Enable the extension in your [configuration file](/topics/configuration)
:::php
SiteTree::add_extension('BookmarkedPageExtension');
:::yml
SiteTree:
extensions:
- BookmarkedPageExtension
In order to add the field to the database, run a `dev/build/?flush=all`.
Refresh the CMS, open a page for editing and you should see the new checkbox.
@ -106,10 +108,12 @@ Add the following code to a new file `mysite/code/BookmarkedLeftAndMainExtension
}
}
Enable the extension with the following line in `mysite/_config.php`:
Enable the extension in your [configuration file](/topics/configuration)
:::php
LeftAndMain::add_extension('BookmarkedPagesLeftAndMainExtension');
:::yml
LeftAndMain:
extensions:
- BookmarkedPagesLeftAndMainExtension
As the last step, replace the hardcoded links with our list from the database.
Find the `<ul>` you created earlier in `mysite/admin/templates/LeftAndMain.ss`

View File

@ -13,12 +13,8 @@ Your extension will need to be a subclass of `[api:DataExtension]` or the `[api:
:::php
<?php
// mysite/code/CustomMember.php
class CustomMember extends DataExtension {
}
// mysite/code/MyMemberExtension.php
class MyMemberExtension extends DataExtension {}
This defines your own extension where you can add your own functions, database fields or other properties you want.
After you create this extension however it does not yet apply it to your object. Next you need to tell SilverStripe what
@ -26,23 +22,27 @@ class you want to extend.
### Adding a extension to a built-in class
Sometimes you will want to add extension to classes that you didn't make. For example, you might want to add the
ForumRole extension to the `[api:Member]` object.
Sometimes you will want to add extension to classes that you can't cleanly subclass.
For example, you might want to add a `MyMemberExtension` class to the `[api:Member]` object.
In order to active this extension, you'd add the following to your [config.yml](/topics/configuration).
:::yml
Member:
extensions:
- MyMemberExtension
Alternatively, you can add extensions through PHP code as well (in your `config.php` file),
which means they can be used in conditional configuration.
:::php
ClassYouWantToOverride::add_extension('Your Class Name');
For example above we want to override Member with a Custom Member so we would write the following
:::php
// add to mysite/_config.php
Member::add_extension('CustomMember');
// Preferred notation: Through the Config API
Config::inst()->update('Member', 'extensions', array('MyMemberExtension'));
// Legacy notation: Through static class access
Member::add_extension('MyMemberExtension');
## Implementation
### Adding extra database fields
Extra database fields can be added with a extension in the same manner as if they

View File

@ -88,19 +88,20 @@ and another subclass for the same email-address in the address-database.
## Member Role Extension
Using inheritance to add extra behaviour or data fields to a member is limiting, because you can only inherit from 1
class. A better way is to use role extensions to add this behaviour.
class. A better way is to use role extensions to add this behaviour. Add the following to your
`[config.yml](/topics/configuration)`.
:::php
Member::add_extension('ForumRole');
// OR
Member::add_role('ForumRole');
:::yml
Member:
extensions:
- MyMemberExtension
A role extension is simply a subclass of `[api:DataExtension]` that is designed to be used to add behaviour to `[api:Member]`.
The roles affect the entire class - all members will get the additional behaviour. However, if you want to restrict
things, you should add appropriate `[api:Permission::checkMember()]` calls to the role's methods.
:::php
class ForumRole extends DataExtension {
class MyMemberExtension extends DataExtension {
/**
* Modify the field set to be displayed in the CMS detail pop-up

View File

@ -245,8 +245,12 @@ also another tool at your disposal: The `[api:Extension]` API.
}
}
// mysite/_config.php
MyAdmin::add_extension('MyAdminExtension');
Now enable this extension through your `[config.yml](/topics/configuration)` file.
:::yml
MyAdmin:
extensions:
- MyAdminExtension
The following extension points are available: `updateEditForm()`, `updateSearchContext()`,
`updateSearchForm()`, `updateList()`, `updateImportForm`.

View File

@ -24,7 +24,6 @@ Or if you want to access variables in the PHP you can do
:::php
$config = SiteConfig::current_site_config();
$config->Title
@ -49,9 +48,12 @@ Create a mysite/code/CustomSiteConfig.php file.
}
Then add a link to your extension in the _config.php file like below.
Then activate your extension in your `[config.yml](/topics/configuration)` file.
SiteConfig::add_extension('CustomSiteConfig');
:::yml
SiteConfig:
extensions:
- CustomSiteConfig
This tells SilverStripe to add the CustomSiteConfig extension to the `[api:SiteConfig]` class.

View File

@ -3,10 +3,10 @@
## Environment Types
Silverstripe knows three different environment-types (or "debug-levels"). Each of the levels gives you different tools
and functionality. "dev", "test" and "live". You can either configure the environment of the site in the
mysite/_config.php file or in your [environment configuration file](/topics/environment-management).
and functionality. "dev", "test" and "live". You can either configure the environment of the site in your
[config.yml file](/topics/configuration) or in your [environment configuration file](/topics/environment-management).
The definition of setting an environment in your `mysite/_config/config.yml` looks like
The definition of setting an environment in your `config.yml` looks like
:::yml
Director:
@ -17,7 +17,7 @@ The definition of setting an environment in your `mysite/_config/config.yml` loo
When developing your websites, adding page types or installing modules you should run your site in devmode. In this mode
you will be able to view full error backtraces and view the development tools without logging in as admin.
To set your site to dev mode set this in your `mysite/_config/config.yml` file
To set your site to dev mode set this in your `config.yml` file
:::yml
Director:
@ -37,7 +37,7 @@ not need to use test mode if you do not have a staging environment or a place fo
In this mode error messages are hidden from the user and it includes `[api:BasicAuth]` integration if you want to password
protect the site.
To set your site to test mode set this in your `mysite/_config/config.yml` file
To set your site to test mode set this in your `config.yml` file
:::yml
Director:
@ -45,7 +45,7 @@ To set your site to test mode set this in your `mysite/_config/config.yml` file
A common situation is to enable password protected site viewing on your test site only.
You can enable that but adding this to your `mysite/_config/config.yml` file:
You can enable that but adding this to your `config.yml` file:
:::yml
---
@ -61,7 +61,7 @@ Live sites should always run in live mode. Error messages are suppressed from th
to email the developers. This enables near real time reporting of any fatal errors or warnings on the site and can help
find any bugs users run into.
To set your site to live mode set this in your `mysite/_config/config.yml` file
To set your site to live mode set this in your `config.yml` file
:::yml
Director:

View File

@ -21,6 +21,7 @@ existing modules or the directories lists in "Core Structure".
| Directory | Description |
| --------- | ----------- |
| `<mysite>/` | This directory contains all of your code that defines your website. |
| `<mysite>/_config` | YAML configuration specific to your application |
| `<mysite>/code` | PHP code for model and controller (subdirectories are optional) |
| `<mysite>/templates` | HTML [templates](templates) with *.ss-extension |
| `<mysite>/css ` | CSS files |
@ -38,7 +39,7 @@ See [themes](/topics/themes)
## Module Structure {#module_structure}
Modules are currently top-level folders that need to have a *_config.php*-file present.
Modules are currently top-level folders that have a `_config.php` file or a `_config/` directory present.
They should follow the same conventions as posed in "Custom Site Structure"
Example Forum:

View File

@ -35,7 +35,7 @@ Create a new file, `~/Sites/_ss_environment.php`. Put the following content in
define('SS_DEFAULT_ADMIN_PASSWORD', 'password');
Now, edit each of your site's configuration file, `~/Sites/(projectname)/mysite/_config.php`. Delete all mention
Now, edit each of your site's configuration file, usually `mysite/_config.php`. Delete all mention
of `$databaseConfig` and `Director::set_dev_servers`, and instead make sure that you file starts like this.
:::php

View File

@ -54,7 +54,7 @@ You can indicate a log file relative to the site root. The named file will have
(an encoded file containing backtraces and things) will go to a file of a similar name, but with the suffix ".full"
added.
`<mysite>/_config.php`:
`mysite/_config.php`:
:::php
// log errors and warnings
@ -67,19 +67,18 @@ added.
In addition to SilverStripe-integrated logging, it is adviseable to fall back to PHPs native logging functionality. A
script might terminate before it reaches the SilverStripe errorhandling, for example in the case of a fatal error.
`<mysite>/_config.php`:
`mysite/_config.php`:
:::php
ini_set("log_errors", "On");
ini_set("error_log", "/my/logfile/path");
## Email Logs
You can send both fatal errors and warnings in your code to a specified email-address.
`<mysite>/_config.php`:
`mysite/_config.php`:
:::php
// log errors and warnings

View File

@ -5,7 +5,7 @@ It is where most documentation should live, and is the natural "second step" aft
* [Access Control and Page Security](access-control): Restricting access and setting up permissions on your website
* [Command line Usage](commandline): Calling controllers via the command line interface using `sake`
* [Configuring your website](configuration): How to configure the `_config.php` file
* [Configuration](configuration): Influence behaviour through PHP and YAML configuration
* [Controller](controller): The intermediate layer between your templates and the data model
* [Data Types](data-types): Types that properties on `DataObject` can have (e.g. `Text` or `Date`)
* [Datamodel](datamodel): How we use an "Object-relational model" to expose database information in a useful way

View File

@ -8,7 +8,7 @@ templating for any initial installation. If you're wanting to add generic functi
project, like a forum, an ecommerce package or a blog you can do it like this;
1. Create another directory at the root level (same level as "framework" and "cms")
2. You must create an _config.php inside your module directory, else SilverStripe will not include it
2. You must create an `_config/` directory inside your module directory, else SilverStripe will not include it
3. Inside your module directory, follow our [directory structure guidelines](/topics/directory-structure#module_structure)
## Tips

View File

@ -7,8 +7,9 @@ directory. In a default SilverStripe download, even resources in 'framework' an
same as every other module.
SilverStripe's `[api:ManifestBuilder]` will find any class, css or template files anywhere under the site's main
directory. The _config.php file in the module directory can be used to define director rules, calls to
Object::useCustomClass(), and the like. So, by unpacking a module into site's main directory and viewing the site with
directory. The `_config.php` file in the module directory as well as the [_config/*.yml files](/topics/configuration)
can be used to define director rules, add
extensions, etc. So, by unpacking a module into site's main directory and viewing the site with
?flush=1 on the end of the URL, all the module's new behaviour will be incorporated to your site:
* You can create subclasses of base classes such as SiteTree to extend behaviour.
@ -85,7 +86,7 @@ Github also provides archive downloads which are generated automatically for eve
The main folder extracted from the archive
might contain the version number or additional "container" folders above the actual module
codebase. You need to make sure the folder name is the correct name of the module
(e.g. "blog/" rather than "silverstripe-blog/"). This folder should contain a `_config.php` file.
(e.g. "blog/" rather than "silverstripe-blog/"). This folder should contain a `_config/` directory.
While the module might register and operate in other structures,
paths to static files such as CSS or JavaScript won't work.
</div>

View File

@ -25,8 +25,8 @@ functionality. It is usually added through the `[api:DataObject->getCMSFields()]
To keep the JavaScript editor configuration manageable and extensible,
we've wrapped it in a PHP class called `[api:HtmlEditorConfig]`.
The class comes with its own defaults, which are extended through the `_config.php`
files in the framework (and the `cms` module in case you've got that installed).
The class comes with its own defaults, which are extended through [configuration files](/topics/configuration)
in the framework (and the `cms` module in case you've got that installed).
There can be multiple configs, which should always be created / accessed using `[api:HtmlEditorConfig::get]`.
You can then set the currently active config using `set_active()`.
By default, a config named 'cms' is used in any field created throughout the CMS interface.

View File

@ -14,7 +14,7 @@ as a .tar.gz file.
1. Unpack the contents of the zip file into the `themes` directory in your SilverStripe installation.
2. Change the site to the theme. You can do this either by:
- Altering the `SSViewer.theme` setting in your `mysite/_config/config.yml`
- Altering the `SSViewer.theme` setting in your `[config.yml](/topics/configuration)`
- changing the theme in the Site Configuration panel in the CMS
3. Visit your homepage with ?flush=all appended to the URL. `http://yoursite.com?flush=all`

View File

@ -20,11 +20,12 @@ It's a `[api:DataExtension]`, which allow it to be applied to any `[api:DataObje
Adding versioned to your `DataObject` subclass works the same as any other extension.
It accepts two or more arguments denoting the different "stages",
which map to different database tables.
which map to different database tables. Add the following to your [configuration file](/topics/configuration):
:::php
// mysite/_config.php
MyRecord::add_extension('Versioned("Stage","Live")');
:::yml
MyRecord:
extensions:
- Versioned("Stage","Live")
Note: The extension is automatically applied to `SiteTree` class.