Mojavi Project

Developing new paths

Archive for October, 2008

October-14-08

FAQ

posted by admin
Frequently Asked Questions

Development related questions can be searched in the forum.

  1. What is Mojavi?
  2. What is MVC?
  3. What are the benefits of MVC?
  4. Why create an MVC framework for PHP?
  5. How is Mojavi licensed?
  6. Where can I get a copy of Mojavi?
  1. What is Mojavi?

    Mojavi is a framework developed in PHP and strongly based on the MVC (model-view-controller) application design paradigm.


  2. What is MVC?

    Model-View-Controller is a design pattern for application development. MVC organizes an application into three separate tiers: one for the model, which represents data and handles business logic, the second for presentation and user input, and the third as a controller, which handles incoming requests and controls application flow.


  3. What are the benefits of MVC?

    An application designed around MVC is easier to manage because the application is split into tiers, which allow for independent development. This promotes code reusability by building models, which are reusable throughout the application.


  4. Why create an MVC framework for PHP?

    Development of PHP scripts without a preconceived plan to manage them is asking for a headache. Before I started developing Mojavi, there weren’t any frameworks that were designed the way I thought a PHP MVC implementation should be designed.


  5. How is Mojavi licensed?

    Mojavi is licensed under the LGPL.


  6. Where can I get a copy of Mojavi?

    Stable and development releases are available on our downloads page.

Tags:
October-11-08

Prepare and protect your server

posted by admin

We just had the unfortunate luck of having to reconfigure our servers that host some of our blogs and websites. We were asked to download some SQL files to our hard drive and the reload them back to the main server. Luckily for us they were able to remotely dial into our PC’s and help us with the configuration without having to send in a tech guy which might have taken hours or even days.
Remote Desktop Service great benefit to the end user like myself in that they can help drive the ship and you get a chance to provide direction and make sure everything is corrected. With companies like Techline.com they offer remote technical assistance where both parties are present on the PC to be able to control the desktop. They offer a nice range of flexible pricing plans and are easy to use and most off security for your transaction.

October-5-08

Converting video to your iPod or iPhone

posted by admin

As the popularity of the iPhone and iTouch increase there has been a greater demand to be able to convert DVDs and other movies files to the accepted MPEG4 format that works for your iPod devices. In our family we have both the iPhone and iTouch and I had been looking for a way to get videos that we own and even those that we made as home movies converted to be able to show on ou devices. There are a lot of choices and the key is to watch out for those programs that promise the world and undeliver. Many of the programs available can contain spyware and viruses and the sole purpose is to have them downloaded on your PC.

At Alldigitalguide.com you can find a nice DVD to iPod Video Converter Review that provides a simple overview of the process and what it entails to actually get those movies to work with your iPod device. Developers have been working long and hard to have programs that work and are easy for everyone to use. When the first iPod video converters came out there were multiple steps and unless you were a Mac genius the chances of you actually getting the final product was very rare. We have atually purchased one of the software packages that they recommend and have found it to be quite simple to convert the files to our iTouch. I would recommend that you do this on a PC with at least 2 GB of ram and a newer dual processor as it will take some time on a slower PC with limited resources.

October-1-08

Creating your first module

posted by admin

Creating Your First Module
A work in progress

This tutorial is a work in progress, so you may find parts that don’t completely fit together.
Module

The module is where the Model and View takes place in the MVC model. For this first example, we will create a very simple module that will move data from a Action to a View and display it on the screen, through a template.

The module is contained within a directory that carries the name of the module. This resides in the modules directory of the webapp directory. Inside the module directory are sub-directories holding the classes that make up the module. Here is the directory hierarchy:

webapp
|
|—modules
|
|—moduleName
|
|—actions
|
|— config
|
|— lib
|
|— models
|
|— templates
|
|— validate
|
|— views

Minimally, you need the actions, config, templates and views directories. However, I prefer to have a blank module created and just copy and rename it. You can get a copy of the blank module (link to be added). I have chosen to call this module Test

Each module must have a module.ini file in the config directory. Here is the module.ini for Test

; +—————————————————————————-+
; | This file is part of the Mojavi package. |
; | Copyright (c) 2003, 2004 Sean Kerr. |
; | |
; | For the full copyright and license information, please view the LICENSE |
; | file that was distributed with this source code. You can also view the |
; | LICENSE file online at http://www.mojavi.org. |
; | ————————————————————————– |
; | MODULE INFORMATION FILE |
; +—————————————————————————-+

[module]

ENABLED = “On”

TITLE = “Getting Started Test Module”

VERSION = “0.1″

NAME = “TestModule”

AUTHOR = “Richard D Shank”

HOMEPAGE = “http://www.mojavi.org”

DESCRIPTION = “A test module”

The module is pretty self explanitory. It is necessary to have ENABLED property set to “On” for the module to be used by Mojavi. Now that we have the module set up, we can work on the classes.
Action

The Action class handles the request for the module. It can be as simple as handling a static html template or a full blown multi-page wizard style form. Just a note to Mojavi 2 users, a significant change from Mojavi 2 to Mojavi 3 is that it is not longer necessary to pass the controller, request and user classes in on many of the methods. These are now accessed through a context class. More on that later.

This is a list of the methods you can use in an Action and an explanation of what they do
execute ()

Note: This method is required in your Action class.

This will execute any application/business logic for the action. This method is reached only after the request methods have been checked and any of the parameters have been validated.

When leaving, the execute() method should tell the controller what view is to be used. This is done by returning a string containing the view name associated with the action or an array of the parent module for the view to be executed, parent action for the view and the name of the view. I will show an example of return both in a later tutorial.
getCredential ()

This is a new feature in Mojavi 3. Basically, a credentials are a privilege array that describes any level of security. They work hand in hand with the security aspects of the User class. For Mojavi 2 users, note that this replaces the old Privileges. But it is also important to know that it can do more than just handle privileges. I will handle the usage of creditials in a later section. For now, it is sufficient to know that we set the creditial requirements for the action inside this method and that it is set to NULL by default.
getDefaultView ()

This is the view that will be executed when a given request is not served by the action. This could happen when a form being displayed for the first time or if we are displaying a static page.

Again, just as with the execute() methoad, a string with a view name or an array of a module/action/view is passed back to the controller. By default it will pass back View::INPUT
getRequestMethods ()

This method will determine what types of requests will be recognized. There are 4 choices:

* Request::GET - Indicates that this action serves only GET requests.
* Request::POST - Indicates that this action serves only POST requests.
* Request::NONE - Indicates that this action serves no requests.

You can also select both GET and POST requests by using Request::GET | Request::POST
handleError ()

Execute any post-validation error application logic.

It also returns the view through a string of the view name or the array of a module/action/view. By default, it passes View::ERROR.
initialize ($context)

You can set up the Action in the initialize() method. In a later tutorial, I’ll give an example of doing this. NOTE: It is worth to note that you must handle the context in the initialize() method. You should do this by

parent::initialize($context);

You also need to return a TRUE or FALSE based on the success of the initialization. By default it is TRUE.
isSecure ()

Does the action require security? TRUE if you do, FALSE otherwise. It is FALSE by default.
validate ()

This is used to manually validate input parameters instead of using a pre-progammed validator. This will also be explain later in the tutorial on validation.
Creating Your First Action

Now that we have an overview of the Action class, we can move forward to creating our first Action. For this example, there isn’t any request to be handled so we can set up a minimal Action.

In naming an action you must use this format Actionname Action.class.php where Actionname is what you are calling this particular action. When you declare your class, it also must have the class name in the same format Actionname Action. For this example, I chose to call this FirstAction.

When creating a new action, at the very least, there has to be an execute() method, even if it does nothing. Also, since we are displaying a non-request page, we don’t need to process any request. We tell the controller this with the getRequestMethods() method, by setting the return value to Request::NONE. Finally, we also need to tell the controller what the default view is going to be. We do this by returning View::SUCCESS in getDefaultView().

Here is what my FirstAction.class.php looks like. I basically just took my BLANKAction.class.php, renamed it to FirstAction.class.php, renamed the class to FirstAction, removed the methods I didn’t need and set the remaining 3 methods to match my needs.

class FirstAction extends Action
{
/**
* Execute any application/business logic for this action.
*/
public function execute ()
{
// we don’t need any data here because this action doesn’t serve
// any request methods, so the processing skips directly to the view
}

// ————————————————————————-

/**
* Retrieve the default view to be executed when a given request is not
* served by this action.
*/
public function getDefaultView ()
{
return View::SUCCESS;
}

// ————————————————————————-

/**
* Retrieve the request methods on which this action will process
* validation and execution.
*/
public function getRequestMethods ()
{
return Request::NONE;
}

You can also return a view from another module. You do this by passing an array with the view information intead of the standard View::INPUT. When you use this you create a two element array. The first element is the module name. The second element is which view you want. It cannot be just the Action name, but the Action name with the specific view.

Here’s an example:

class MyClass extends Action
{

function execute()
{

$returnView[0] = MyModule;
$returnView[1] = DoSomethingInput;
-or-
$returnView[1] = DoSomethingError;
-not-
$returnView[1] = DoSomething;

return $returnView
}
}

View

I’ll add more to this later, describing the View class.

For now, all we need to use is the execute() method.
Creating the View

The class name should be in this format ActionnameViewtype View. Again Actionname is the name of the action in the module. Viewtype is the view type that was passed to the controller in the action. Both Actionname and Viewtype are capitialized. This is a list of the predefined view file types and their naming convention.
Internal Name Class and File Name
ALERT Alert
ERROR Error
INPUT Input
SUCCESS Success

Mojavi 2 users ; the naming convention on the file has changed slightly. Before there was an underscore between Actionname and Viewtype. Now, there is no underscore in between, and the Viewtype is capitialized.

For this example, I called my view FirstSuccessView and named the file FirstSuccessView.class.php.

Here’s the code

class FirstSuccessView extends PHPView
{
/**
* Execute any presentation logic and set template attributes.
*/
public function execute ()
{

// set our template
$this->setTemplate(’FirstSuccess.php’);

// set the title
$this->setAttribute(’title’, ‘Getting Started First Test Page’);

// set the message that is to be passed
$this->setAttribute(’passedData’, ‘Hello World!’);

}

}

Template

You also need a template to display the information. I stayed with the naming convention and called my file FirstSuccess.php.

Here is the code for that

This is the result of my first test. I have created a module, action, view and
template. I have successfully passed data from the view to the template.

This is what I passed:
That is all for now.

Notice at the first and last line I include a header.php and footer.php. I used this to show how you could have a uniform look across the entire site and how you could do that. Mojavi uses a global template directory in your webapp directory. It is defineed as MO_TEMPLATE_DIR and it called templates. I added the following files to the includes sub-directory in the global template directory.
header.php

footer.php

Wrapping it up

Finally, there are a couple of ways you can test this module. The first and quickest way is just to instruct the controller using the url. Just add the module and action. Here’s what it would look like http://yourserver.com/index.php?module=Test&action=First.

The second way is by changing the default module in the settings.ini file in the webapp/config directory.

Under [.actions] you will find the default module. Find the following two lines and change the default module and action.

DEFAULT_MODULE = “Default”
DEFAULT_ACTION = “Index”

After you change the default module and action it should look like this

DEFAULT_MODULE = “Test”
DEFAULT_ACTION = “First”

You are now ready to test your code. Just point your browser to the index.php and see the fruit of your labor.

Technology Blogs - BlogCatalog Blog Directory