Silverstripe v4 MVC Directories? - silverstripe

I'm Wondering Why There is no "Models / Views / Controllers" Directories Inside SS4 Main Directory? It's Seems Like Everything Should Go Inside "mysite/code" .. How To Accomplish MVC Style?

MVC is more of a software-architectural pattern, not how you organize files. There are only a few assumptions the SilverStripe framework makes on how you should organize your code:
Model
With SilverStripe 4, the default code folder for every module is named src or code. In that folder you're free to organize your files as you see fit. Ideally you build your folder structure in a PSR-4 compliant way, so that your folder-names match with your namespaces.
Controllers
Same as with Model classes, you can put your controllers anywhere you want.
There's a default assumption for Page classes though. These expect that the matching controller has the same namespace as the page. So if your page is named: Company\Module\Pages\MyPage, the framework would look for Company\Module\Pages\MyPageController.
You're free to override that though, by implementing the getControllerName method on your Page and return the FQCN for the controller to use.
Views
Also known as "templates" should be in a templates folder. Each module (your mysite folder is also a module) can have a templates folder.
In addition to this, you can have themes. Themes usually bundle templates, css and other assets. In the themes folder you can have multiple theme folders, each one can have a templates folder.

Related

Where do custom components go in Next.js 13 file structure?

With this version, are you meant to create a Components/ folder inside the app folder? Or can I add new components anywhere in the file structure?
I currently have a components/ folder nested inside the app/ which seems to work fine. But I'm not sure if this can cause issues or if there is a better approach.
Can each "page" get it's own components/ folder?
In NextJS anything you keep inside the pages folder is considered a page or subpage, lets's say you have created the components folder inside one of the pages folders like below. Then you can access the components inside this folder as pages, so you can access this component with the below URL.
https://baseUrl/admin/components/componentName
So in NextJs, everything we put inside the pages folder is considered an individual page. If you want a separate space/folder for components you can create feature-level components outside the page folder like below.
Now components added in this feature folder are not accessible as a page and you can reuse these components as you want.
I hope this answered your question. Happy coding!

Use bundle error templates in Symfony 3 app

I have a MyBundle bundle which I use in many Symfony applications.
This bundle provides common things which are shared across these applications, such as Controllers, Entities, templates, etc.
I would like the bundle to provide error templates as well.
I tried to put the templates in MyBundle/Resources/TwigBundle/views/Exception folder but the application does not use them.
When I copy TwigBundle folder from MyBundle/Resources into app/Resources then the templates are used as expected. However I do not want to copy the templates into every application's app/Resources folder.
Is it possible to override error templates using MyBundle/Resources instead of app/Resources?
TwigBundle always by default checks directory app/Resources/TwigBundle/views/Exception/ for templates.
If you want to use custom directory you have to override ExceptionController.
You can do this in config
// app/config/config.yml
twig:
exception_controller: MyBundle:Exception:showException
Default Twig ExceptionController can be found here.
Documentation

How to put a Template together with Ruby on Rails

I have a template, one of those you could buy, with many css/js/images, very beautiful.
But I have to control these pages with Ruby on Rails, which I am still learning.
The template files have many directives for other files and folders.
I am trying to understand the Assets Pipeline and I am feeling that it looks not good.
There are dozens of css files, with the directives for many images that are placed in other folders.
I am very scared to be straightforward.
I am not the project owner, I just have these two requirements:
Use this template
Build the system in Ruby on Rails
Could someone indicate me the correct way to get along with this situation.
Thanks a lot.
There is no direct solution to this, but may be this can help: install_theme gem. I haven't used it but the link shows how to use an html/css/js theme in rails application.
Friends,
There is a solution for dummies!
I am feeling so fool.
Inside Rails folders, there is a folder called public
We just have to put our css/js/images inside this folder.
For example, in my template, the index.html was in the same folder then a folder called assets which has sub folder css, js, images
So, the files need for index.html were (relatively to it) in assets/css/... or assets/js/...
Thus, all I had to do was copy my whole folder assets to inside the public directory below Ruby on Rails files.
I found it here:
The Asset Pipeline
I am sorry for the dummy question.
Thanks a lot!

What is the best place of main assets declared in `base.html.twig`

Each bundle has it's own public directory to store assets (css/js/images).
Now what is the best place for assets used in app\Resources\views\base.htl.twg?
How dose Symfony understand to populate them to public?
usually the assets of templates available in the app/Resources/view directory(like base.html.twig) are placed directly in a subdirectory of the web root like web/includes/css/main.css and called with asset('includes/css/main.css').
If you don't like it, you can easily create your own bundle to store the app assets.
I suggest you to create a DesignBundle to store all base template and assets. This method permit you to share your configuration with other application.

ASP.NET MVC Web structure

Database http://img443.imageshack.us/img443/6049/structure.gif
This is database structure. It is used to build simple cms in asp.net mvc. Before I run deeper into developing site, I want to make sure if this would be "correct" web structure:
Articles:
Controllers folder: Create controllers ArticleCategoryController and ArticleController
Models folder: ArticleCategoryRepository and ArticleRepository
View folder: ArticleCategory folder (Create.aspx, Edit.aspx, Index.aspx, Details.aspx); Article folder (Create.aspx, Edit.aspx, Index.aspx, Details.aspx)
Photos:
Controllers folder: Create controllers PhotoAlbumController and PhotoController
Models folder: PhotoAlbumRepository and PhotoRepository
View folder: PhotoAlbum folder (Create.aspx, Edit.aspx, Index.aspx, Details.aspx); Photo folder (Create.aspx, Edit.aspx, Index.aspx, Details.aspx)
and so on...
Is there a better way or this is ok?
Thanks.
Ile
There are lots of ways to organize your controllers and views. I usually create a controller for each full view.
The main comment I have here is about the model. I do not like putting model code into the models folder of the mvc web project unless they are view models or somehow directly related to the web tier of my app and inapplicable to a non web context. In my opinion, you are better off putting things like domain classes, repositories services, etc in a separate assembly or group of assemblies. This way you can swap out the front end with silverlight, or some other technology and continue to leverage your core domain code. Not only is this beneficial for swapping out front ends which is sometimes rare, but you can use the core domain dll for batch files or command line utilities if you ever need to do batch type operations outside of the context of your website.

Resources