DO I UNDERSTAND MVC CORRECTLY?
I've read many posts by the user teresko and I think I finally understand the real concept of modern MVC. I made a diagram of how I understand it to be, I'm hoping somebody can confirm this for me and that maybe this diagram will help some other users.
IS MY PLANNED DIRECTORY STRUCTURE "SMART"?
Also I'd like to get into folder structure. I'm not too sure that I plan on using a very smart/efficient way of structuring them. In my root directory I have 4 folders. The model folder contains 3 subdirectories called data_mappers, domain_objects and services. The presentation folder contains 2 subdirectories naturally called views and controllers. The 3rd folder in my root directory is one of the ones I'm less sure on called lib and contains another 3 sub-folders, scripts, themes, and templates (is this a good place for templates that will be called by view?). And the last folder which I have is called config (if anybody can think of a better name suggestions are welcomed). This is where I will place the router and base classes and any files of that type. I'm not just going for functionality with my framework, I want it to be technically sound, any suggestions/advise are welcome, I want to make sure my understanding up to this point is correct before I start making the index and router etc so I don't have to start over once again. Thanks
IS THIS A GOOD WAY TO GO ABOUT MULTI-LANGUAGE SUPPORT IN MVC?
(A little off topic, but I need to incorporate this into planning my MVC framework, it may be helpful to other users, and in order to answer the question clearly and concisely the structure of the website needs to be understood and it happens to be described in detail in the above)
My website must be available in English and French, both of which I happen to speak. I plan to create two more sub-folders within the templates folder, one called en and and another fr and simply place all of the English templates in en folder and translate them into French and place them in fr folder and set up the website so www.mywebsite.com/en/home shows the template in English and www.mywebsite.com/fr/home shows the template in French.
There will be a main language selection page that will redirect you to either en or fr. Then, I plan to store the 2 letter language code in a $_SESSION variable. The view will use this $_SESSION variable to pick which template to display. This is the way I had done it on the old version of my website. Is this a good way of accomplishing multi-language support in MVC or is there some better way?
What if I want to make the url also appear in French? If I put the view files inside more subfolders and instead of naming them like this: "/presentation/views/news/news.php" name them like this: "/pre sentation/views/news_nouvelles/news.php" and then make the router (urls and routing is one of my weaknesses, but I will learn on my own ;) store everything before the "_" in a variable corresponding to the English url, and everything after corresponding to the French url. This is just a theory and I have not attempted what is in this last paragraph yet, the multi-language support is more for discussion than a question, although once again, it is relevant because a thorough understanding of my framework is needed to answer/discuss language support.
Routing
Basically, by the time your code gets to calling stuff on controller, you should have fully initialized request instance, that has recognized language from the URL and translated all the parts of input into something useful for creating instances.
At this point you would have split the user's query (from example:
'/presentation/view/dernières/nouvelles'
) into recognized segments, based on pattern that was recognized.Lets take for example, that matted pattern was in config defined as:
/presentation[[/:action[/:filter]]/:resource]
And the produced result is:
Internationalization
The translations will usually be stored either in database or in some configuration file. If your service factory is already initialized at this point, then you can dip into that for facilitating the interaction with this stored config:
What you would collect from stored config by translating it would be
translation
of the value that user provided in querylanguage
in which that query fragment was writtentitle
which corresponds to the fragmentThe data that you get back would look something like:
These entries are used for two tasks:
By the end of this you should have a translated ll the parameters in the
Request
instance and, based on some criteria, determined and addedlanguage
parameter to that request.my 2 cents