Hey. I'm new with the development of bigger systems like silverstripe and the complexity is quiete overwhelming for me. At the moment I'm tyring to find out how the plugin structure works. But the documentation is not helpful for me at the moment because of general understanding problems. What i would need is something like an overview over all neccessary files in a module and a description what they are good for. How do modules interact with each other, how do you address frontend and backend? And how does the logic interact with the whole thing? I'm aware that this is nothing that can be answered in a single post, but i need a lead. Something i can start with. Maybe a super simple hello world module ...
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Welcome to the forums,
First: Let's make sure you did the tutorials and understood all of it.
http://doc.silverstripe.org/framework/en/tutorials/1-building-a-basic-site
http://doc.silverstripe.org/framework/en/tutorials/2-extending-a-basic-site
http://doc.silverstripe.org/framework/en/tutorials/3-forms
Second: Basically, a module is a folder in your project and in this folder is at least a "_config" folder or a "_config.php" file. This isn't doing anything at the moment, but technically it's is module.
http://doc.silverstripe.org/framework/en/topics/module-development
Third: To be consistent, we recommend a certain folder structure for all modules. So it's obvious which files go to where.
root directory/
- cms/ <-- the cms
- framework/ <-- the framework
- mysite/ <-- your base project folder
- silverstripe-helloworld/ <-- your module
- _config/
- code/
- css/
- images/
- javascript/
- lang/
- templates/
- tests/
http://doc.silverstripe.org/framework/en/topics/directory-structure#module_structure
Fourth: Let's make the module output "Hello world!" when visiting the url "localhost/my-silverstripe-demo-folder/helloworld/"
http://doc.silverstripe.org/framework/en/topics/controller
First, we need a controller class which takes care of the logic.
silverstripe-helloworld/code/HelloWorld.php
<?php
class HelloWorld_Controller extends Controller {
private static $allowed_actions = array('index');
public function index(SS_HTTPRequest $request) {
return "Hello World!";
}
}
Then we need a configuration file, where we map the route "helloworld" to the "HelloWorld_Controller".
silverstripe-helloworld/_config/HelloWorld.yml
---
Name: helloworldroute
After: framework/routes#coreroutes
---
Director:
rules:
'helloworld//$Action/$ID': 'HelloWorld_Controller'
Then we need to tell SilverStripe to register those new files by adding a "?flush" at the end of the URL. "localhost/my-silverstripe-demo-folder/?flush".
At last, we see our HelloWorld module in action by visiting "localhost/my-silverstripe-demo-folder/helloworld/". Et voilà, "Hello World!"
Thank you very much for your very detailed post. It helped me indeed to get a basic understanding of the cms. Allow me to summarize my current understanding: Modules MUST be in the root directory of the silverstripe installation. There silverstripe is searching for new folders with a _config file or a config folder inside. These files (or folders) map the controllers to a specific url. Then the controller on his end defines actions on the database and the template (or in other words what templates to use and how to manipulate it).
But unfortunately i wasn't able to test (or better play with) your hello world module. I just got this error message:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Unable to parse line 4 (--- ).' in /opt/lampp/htdocs/silverstripe/framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlParser.php:265 Stack trace: #0 /opt/lampp/htdocs/silverstripe/framework/core/manifest/ConfigManifest.php(275): sfYamlParser->parse('--- \nName: hell...') #1 [internal function]: SS_ConfigManifest->addYAMLConfigFile('HelloWorld.yml', '/opt/lampp/htdo...', 2) #2 /opt/lampp/htdocs/silverstripe/framework/filesystem/FileFinder.php(158): call_user_func(Array, 'HelloWorld.yml', '/opt/lampp/htdo...', 2) #3 /opt/lampp/htdocs/silverstripe/framework/core/manifest/ConfigManifest.php(215): SS_FileFinder->find('/opt/lampp/htdo...') #4 /opt/lampp/htdocs/silverstripe/framework/core/manifest/ConfigManifest.php(103): SS_ConfigManifest->regenerate(false) #5 /opt/lampp/htdocs/silverstripe/framework/core/Core.php(119): SS_ConfigManifest->__construct('/opt/lampp/htdo...', false, true) #6 /opt/lampp/htdocs/sil in /opt/lampp/htdocs/silverstripe/framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlParser.php on line 265
Anyone out there who knows what i am making wrong?
Modules MUST be in the root directory of the silverstripe installation.
Yes, but not quite. They can be anywhere in your project. For example if you have a look in the "framework" folder, there is a "admin" folder which also has a "_config.php" file, so it's technically a module of its own.
These files (or folders) map the controllers to a specific url.
The config files can contain any configuration setting. It's the "Director: rules" setting which map a URL to a controller.
Then the controller on his end defines actions on the database and the template
SilverStripe is strict MVC (Model, View, Controller). The Controller defines actions and the Model defines what is stored in the database. Then the Controller calls up a template and the View renders the template with the Model.
http://en.wikipedia.org/wiki/Model-view-controller
Of course, you can mess it all up and do what you want, but it's prudent to follow that system.
Anyone out there who knows what i am making wrong?
Yes. The forum post messed up my formatting. There's supposed to be to intend indent in the .yml file. As in:
---
Name: helloworldroute
After: framework/routes#coreroutes
---
Director:
rules:
'helloworld//$Action/$ID': 'HelloWorld_Controller'