Version 2 (modified by steinwinde, 11 years ago) (diff)

Replaced MediaWiki formatters by trac formatters.

Short introduction to development based on platform PT

What happens with the browser request?

We suppose your URL looks like this:


1. /htdocs/index.php

Whatever URL you call, this is your entry point. Reason is the RewriteRule? in the file /htdocs/.htaccess. index.php reads basic initialization files and sets itself several important constants. Lots of files are loaded (but not instantiated), e.g. the modules (see /modules).

2. /build/rox/rox.ctrl.php

At one point in index.php the Rox controller is instantiated. The constructor of rox.ctrl.php is used for initialization of things you need on every page. We can't tell you exactly, what's happening, but if you skip the instantiation of Rox at this stage, you get weird redirects, may be cookie problems too. If you look at the constructor of the Rox controller you see lots of other things happening. We'll not go into it, as your URL wasn't http://yourfqdn/rox, but http://yourfqdn/yourapp. For now you may forget about the Rox application.

3. /build/yourapp/yourapp.ctrl.php

A few lines later in index.php, your app (with the name "yourapp") is dynamically determined, your controller is instantiated and its index method is called. Here you go! The index method of the controller of your application is the steering wheel of your code. If your application accepts different types of calls, you'll probably want to include a switch-case block in this method. While instantiating your controller, the model and the view of your application have hopefully been instantiated too. So here you can freely connect these three classes to build the response you want.

An incidental remark: your application

Your application consists in 4 files residing in a new directory /build/yourapp.

  1. yourapp.model.php (model)
  2. yourapp.view.php (view)
  3. yourapp.ctrl.php (controller)
  4. build.xml

ad 1.

The model is, where you build query strings for the database and execute them. If you start to write a new application, create the model file with an empty constructor. Best just copy and adapt /build/chat/chat.model.php, a model for an application without interest in database stuff - quite empty :)

Keep in mind: The model class is for database access. No HTML stuff in here at all! And avoid any logic in this place. All methods should return the desired value (often an array).

As the check of input in form fields is often involving database requests, you may place check methods in the model class.

ad 2.

The view class is a list of methods, which display things. As displaying things (by HTML) takes a lot of space, these methods usually look like this:

  function displayPage() {
    // do some initialization of variables
    require '/templates/apps/yourapp/yourpage.php';

As you can see, the HTML is somewhere else. The view class may be responsible for displaying different large pages. It wouldn't make sense to put the HTML in one class.

Methods in the view class rarely return values. They almost always just include the stuff to be displayed to the user.

ad 3.

The controller and its index method is assigning requests to their correct methods. As I already mentioned, the index method is the first method called in your application.

ad 4.

Check out build.xml of other applications and write your own in a similiar fashion. It's mostly a copy-paste job.

4. /templates/apps/yourapp/yourpage.php

Via the index method of your controller and one of the methods in your view class, eventually yourpage.php with all the HTML and stuff gets executed. This page shouldn't include any logic (which is the business of your controller) and it's absolutely forbidden to include database calls here. But the page might instantiate other applications, that will include content.

5. /templates/misc/page.php

May be you recognised something is missing. The content your application produced is only the main part of the page. Header, footer and other stuff around is provided by /templates/misc/page.php. Check page.php to easily find where your content is included. Search for the method $Page->content. It's the same page object, you may find in many switch-case clauses in controler methods, typically used like this: $Page = PVars::getObj('page');. So if you change page.php, this effects all pages of BeWelcome.

[[Category:Platform PT]]