Quantcast
Viewing latest article 4
Browse Latest Browse All 11

ASP Framework 0.4 Example

Configuration

To start out browse to “/application/config/config.asp” and edit a few of the items. Most of these can be left at their default state.

Setting up

All URI’s are redirected to the “default.asp” page and parsed to find the appropriate controller, method, and parameters. By default all controllers are stored in “/application/controllers/*.asp” they can be in sub directories if you wish, the router will still be able to find it. Each controller is a class with methods. It is only allowed to have 1 parameter, if more exist, they will be compiled into a single array. There is a default method if none is chosen, which is setup in the config file.

Global variables

There are a few global variables besides the ones in the config file.

helperClass /  helper
modelClass / model
viewClass / view
frameworkVersion

Example Controller

<%
    ' /application/controllers/default.asp
    ' www.example.com/ASPMVC/default/
    Class defaultController
        Public Function index(byRef myParams)
            ' Code here
        End Function
    End Class
%>

Views

You can access the view with a simple syntax:

view.retrieve(fileName, willReturn)

The filename is the name of the file excluding the prefix and suffix defined in the config file. If “willReturn” is true is will return all the code for you to execute, if not it will execute itself. Here is an example:

Execute view.retrieve("404", true)

Executing it yoruself allows you to share variables with the file since your variables are local to your class unless defined as globals.

Helpers

Helpers allow you to include library files or a file with groups of functions. This can aid you with common tasks shared between controllers or models. I included a built in helper “eventQue” which is an observer and allows you to “bind” functions and subs to events then trigger them. Here is an example:

<%
    ' Create myQue
    Dim myQue
    Execute helper.retrieve("eventQue", true)
    Set myQue = new eventQue
 
    ' Bind event to function
    Call myQue.bindObjFunction("header", Response, "write", "<script type='text/javascript'>alert('Hooks are enabled.')</script>")
 
    ' Call event
    myQue.trigger("header")
%>

Models

I believe this is where the most improvement with v0.5 was made. I was not pleased at all with the syntax of the last version. Models have the same syntax as the previous version. Here is an example:

<%
    Class tableModel
        Public Function getTables(ByRef fn_recordSet)
            fn_recordSet.Open "SELECT name FROM sys.tables", dbconn, 0, 1
        End Function
    End Class
%>

Inside the controller you can access the model using the following syntax:

<%
    Dim recordSet1
    Set recordSet1 = Server.CreateObject("ADODB.Recordset")
 
    model.retrieve("table").getTables(recordSet1)
    Do While Not recordSet1.EOF
        Response.write("<br />" & recordSet1("name"))
        recordSet1.MoveNext
    Loop
    recordSet1.Close
%>

The specific model is stored inside of the parent “model”. When you retrieve it looks to see if it already has that model, and if so returns it. If you want to cache it yourself, the method “.retrieve” will return it for you.

<%
    Dim recordSet1, tableModel
    Set recordSet1 = Server.CreateObject("ADODB.Recordset")
    Set tableModel = model.retrieve("table")
 
    tableModel.getTables(recordSet1)
    Do While Not recordSet1.EOF
        Response.write("<br />" & recordSet1("name"))
        recordSet1.MoveNext
    Loop
    recordSet1.Close
%>
BlaineSch ASP Framework
v0.4_ASPFramework.zip
Version: v0.4

Viewing latest article 4
Browse Latest Browse All 11

Trending Articles