wiki:HelloWorld

Your Hello World Applicationclick here

Say hello with html formated text from an extern fileclick here

Say hello with a simple database queryclick here

Say hello in many languages with a database queryclick here



Your Hello World Application

(under construction, please help to improve this site) caution: bad English & no warranty :)

Let`s write a Hello World application for BW-Rox:
We call this modul "Hello" and create a new folder in the build directory therefore.

mkdir build/hello


We need to create the following files:

Filename Path
hello.ctrl.php build/hello/hello.ctrl.php
hello.model.php build/hello/hello.model.php
hello.view.php build/hello/hello.view.php
build.xml build/hello/build.xml



In a first step we are going to say hello without a database query. This means we don`t neet the model file at the moment. Have a look at the file hello.model.php. It is more or less empty. There is only a class called Hello with a construct function.

hello.model.phpcomments
<?php php start sign
/*Copyright (c) 2007 BeVolunteer
This file is part of BW Rox.
BW Rox is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

BW Rox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/> or
write to the Free Software Foundation, Inc., 59 TemplePlace - Suite 330,
Boston, MA 02111-1307, USA.
*/
the licence
(commented out with /* ... */)
/
* hello model
* @package hello
* @author mahouni200000 BeVolunteer BeWelcome
*/
comments about name of the
package and creator
(commented out)

class Hello extends PAppModel {
the model class Hello

public function __construct() {
parent::__construct();
}
the constructor function of the model class Hello




}
the emptyness
?>php end sign



What we need is the file hello.view.php. There we can write our message to the world. This will be done with the function "hello()". Its job is just to say hello.

hello.view.phpcomments
<?php
/*the licence and other comments etc aren`t repeated here*/

class HelloView extends PAppView {
private $_model;

the HelloView class will
take the standard View Class for Applications
in PT and extends it with the following stuff

public function __construct(Hello $model) {
$this->_model = $model;
}
the construction function for our Hello View Class

public function hello() {
echo 'hello world, be welcome!';
}
the name of our function to write the hello message is hello,
this function will print our text with the echo command

}
?>



Finally we need a place where we call the just created function hello() from the class HelloView in the file hello.view.php to show our text
on the website. This will be done in the command file hello.ctrl.php.
In this file the rest of BW-page with its head, sidebar and disclaimer etc is loaded too.

hello.ctrl.phpcomments
<?php
class HelloController extends PAppController {

private $_model;
private $_view;

public function __construct() {
parent::__construct();
$this->_model = new Hello();
$this->_view = new HelloView($this->_model);
}

public function __destruct(){
unset($this->_model);BR] unset($this->_view);[[BR? }

the HelloController class will
take the standard Controller Class for Applications
in PT and extends it with the following stuff:
*the variables $_model
(creates an Object for db query, we don`t need it at moment)
* the variable $_view
(creates a HelloView object to call the function in hello.view.php
* a constructor and destructor function
*and finally our index function to controll wht our Hello Application will do.

public function index() {
ob_start();
$this->_view->hello();The index function calls the hello function from the file hello.view.php

$str = ob_get_contents();
ob_end_clean();
$Page = PVars::getObj('page');
$Page->content .= $str;
}
The output for our Hello Application is written in the variable $str and the
content from the rest of the BW page is added with the $Page variable

}
?>



Finished! let`s test it! ah no, before we test it: the file build.xml needs to be changed aswell and should look like this:

<?xml version="1.0" encoding="utf-8"?>

<build>

  <app name="Hello"/>

  <files>

    <file class="HelloController">hello.ctrl.php</file>

    <file class="Hello">hello.model.php</file>

    <file class="HelloView">hello.view.php</file>

  </files>

</build>

Save the files, open your browser and go to http://localhost/bewelcome.[[BR]]

Here you are on the BW main page.
Now we want to go to our hello world application page. The link could be in the tab bar where you already can see the other BW moduls like the forum, the groups, the FAQ etc.
But it`s not necessary. We can go to our application with the following adress:
http://localhost/bewelcome/htdocs/hello[[BR]]

and there we are!



next step:

Say hello with html formated text from an extern fileclick here




Last modified 10 years ago Last modified on Mar 6, 2008 3:16:27 AM

Attachments (1)

Download all attachments as: .zip