My journey towards learning Mach-II framework
Few days back, I have added post regarding CF frameworks.
In this post we are going to understand what Mach-II is and what this beautiful framework provides.
There is already a superb Github directory from where you can learn Mach-II.
This post will help you to get familiar with some basics of Mach-II and early hurdles you face if you are a beginner.
Below points will cover whatever I've learned so far in Mach-II.
Let's begin: -
What Mach-II is ?
Flow of Mach-II Application:
I am still driving deeper into Mach-II framework, hope I will be coming with some more post related to Mach-II soon.
Happy Learning :)
Few days back, I have added post regarding CF frameworks.
In this post we are going to understand what Mach-II is and what this beautiful framework provides.
There is already a superb Github directory from where you can learn Mach-II.
This post will help you to get familiar with some basics of Mach-II and early hurdles you face if you are a beginner.
Below points will cover whatever I've learned so far in Mach-II.
Let's begin: -
What Mach-II is ?
- MVC framework for ColdFusion
- Benifit of MVC : Separation of codes into different layers which help to reuse and organize your code better using the Model(mainly CFCs), View(shows your content) and Controller(which link Model and Views)
- In Mach-II controller comprises of plugins,listeners and filters
- Object Oriented F/W
- Event Driven Framework
- mach-ii.xml where all configuration needs to be done.
- XML contains : Properties, Events, Listeners, Page Views, Filters, Plugins
- II stands for Implicit Invocation
- As Mach-II is an event driven framework, so all events are handled though event handlers which in turn announced a component for which event is registered.
- Know More here Implicit-Invocation-Architectures in MVC
- Easy to maintain and provide flexibility in developing robust application.
- First download Mach-II f/w code and skeleton from
MachII Github or Mach-II home - A basic folder structure which I kept up while learning Mach-II
- Once code downloaded, now we have to run mach-II application based on where you kept our framework files and skeleton files.
If you are keeping f/w files outside web root, then we have to add a mapping in CF administrator. You can also extend Mach-II f/w codes to setup your mach-ii f/w environment.
Here is the link which shows you various ways to setup your mach-ii application - Above Image shows my application folder comprises of both f/w codes + skeleton.
- I pointed this directory as a Virtual Directory in my IIS and named as "mach2test"
- Now we need to open /config/ mach-II.xml. In property applicationRoot we have to specify the root of our application.
<property name="applicationRoot" value="/mach2test" /> - Now, once we have added value for applicationRoot, we have to add mapping or inherit f/w codes using extends attribute.
So for this I have added "MachII.mach-ii" in application.cfc to inherit mach-ii.cfc
<cfcomponent displayname="learnMach-ii" output="false" extends="MachII.mach-ii"> - Now code setup is over, you are ready to run your first o/p in the browser.
http://localhost/mach2test/index.cfm. If you have downloaded Mach-II skeleton then first o/p will be Hello Mach-II!
Flow of Mach-II Application:
- All Mach-II request flows from index.cfm because it follows pattern called Front Controlerl
- Wiki: It provides a centralized entry point for handling requests.
- As Mach-II is event driven in nature, so everything goes on by calling an event which creates event objects. Let's look for one example to get a clear Idea on Mach-II flow.
- Say for example: If you have a basic login page in your application
- URL : http://localhost/mach2test/index.cfm?event=login. So first request goes to central page index.cfm and start looking for Mach-II.xml
- As we are calling an event called login (If we don't specify any eventParameter then defaultEvent will execute) so It will look for event-handers where an event is login
- Now event handler told to open a view called login.cfm.
- In login.cfm - we have one form whose action calls "index.cfm?event=checkLogin"
- Now, once again flows go to Mach-II.xml and look for checkLogin event. checkLogin event handler calls listener loginListener which looks for validateLogin method present under loginComponent CFC which resides under the model.
- validateLogin() return success/failure and announces an event loginSucess and shows home.cfm or loginFailure which shows error message.
I am still driving deeper into Mach-II framework, hope I will be coming with some more post related to Mach-II soon.
Happy Learning :)
Looking for someone who knows Mack-II to help troubleshoot a server migration. Any direction appreciated. Jeff
ReplyDelete