Changes between Version 1 and Version 2 of HelloWorld


Ignore:
Timestamp:
Feb 4, 2008, 7:56:46 PM (11 years ago)
Author:
mahouni
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HelloWorld

    v1 v2  
    2424[[BR]]
    2525In 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 [wiki:HelloModel/ hello.model.php]. It is more or less empty. There is only a class called Hello with a construct function.
    26 
    27 [[BR]]
    28 
    29 ||'''hello.model.php'''||'''comments'''||
    30 ||<?php  ||      php start sign||
    31 ||/*Copyright (c) 2007 !BeVolunteer[[BR]]This file is part of BW Rox.[[BR]]BW Rox is free software; you can redistribute it and/or modify[[BR]]it under the terms of the GNU General Public License as published by[[BR]]the Free Software Foundation; either version 2 of the License, or[[BR]](at your option) any later version.[[BR]][[BR]]BW Rox is distributed in the hope that it will be useful,[[BR]]but WITHOUT ANY WARRANTY; without even the implied warranty of[[BR]]MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the[[BR]]GNU General Public License for more details.[[BR]][[BR]]You should have received a copy of the GNU General Public License[[BR]]along with this program; if not, see !<http://www.gnu.org/licenses/> or [[BR]]write to the Free Software Foundation, Inc., 59 !TemplePlace - Suite 330, [[BR]]Boston, MA  02111-1307, USA.[[BR]]*/[[BR]]|| the licence [[BR]](commented out with /* ... */)||
    32 ||/**[[BR]]* hello model[[BR]]* @package hello[[BR]] * @author mahouni200000 !BeVolunteer !BeWelcome[[BR]] */|| comments about name of the [[BR]]package and creator[[BR]] (commented out)||
    33 ||[[BR]]class Hello extends PAppModel { [[BR]]|| the model class Hello ||
    34 ||  [[BR]] public function !__construct() {[[BR]]       parent::!__construct(); [[BR]]    }[[BR]]||the constructor function of the model class Hello||
    35 ||[[BR]][[BR]][[BR]][[BR]]}|| '''the emptyness'''||
    36 ||?>||php end sign
    3726[[BR]]
    3827[[BR]]
    3928
    4029What we need is the view file. There we can write our message to the world:[wiki:HelloView/ hello.view.php]. This will be done with the function "hello()". Its job is to say hello.
    41 
    42 ||'''hello.view.php'''||'''comments'''||
    43 ||<?php ||
    44 ||/*the licence and other comments etc aren`t repeated here*/||||
    45 ||[[BR]]class !HelloView extends PAppView {[[BR]]    private $_model;[[BR]]||[[BR]]the !HelloView class will [[BR]]take the standard View Class for Applications[[BR]] in PT and extends it with the following stuff||
    46 ||[[BR]]    public function !__construct(Hello $model) {[[BR]]        $this->_model = $model;[[BR]] }|| the construction function for our Hello View Class||
    47 ||[[BR]]    public function hello() {[[BR]]        echo 'hello world, be welcome!';[[BR]]    }||the name of our function to write the hello message is '''hello''', [[BR]]this function will print our text with the echo command||
    48 ||[[BR]]}[[BR]]?>||||
    49 
    5030[[BR]]
    5131[[BR]]
     32
    5233Finally 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[[BR]] on the website. This will be done in the command file [wiki:HelloController/ hello.ctrl.php].[[BR]]
    5334In this file the rest of BW-page with its head, sidebar and disclaimer etc is loaded too.
    5435[[BR]]
    55 ||'''hello.ctrl.php'''||'''comments'''||
    56 ||<?php ||
    57 ||class !HelloController extends PAppController {[[BR]][[BR]]    private $_model;[[BR]]    private $_view;[[BR]][[BR]]    public function !__construct() {[[BR]]        parent::!__construct();[[BR]]       $this->_model = new Hello();[[BR]]        $this->_view  = new !HelloView($this->_model);[[BR]]    }[[BR]][[BR]]   public function !__destruct(){[[BR]] unset($this->_model);[[BR]        unset($this->_view);[[BR]]    }[[BR]][[BR]]||the !HelloController class will [[BR]]take the standard Controller Class for Applications[[BR]] in PT and extends it with the following stuff:[[BR]]*the variables $_model[[BR]]    (creates an Object for db query, we don`t need it at moment)[[BR]]* the variable $_view[[BR]] (creates a !HelloView object to call the function in hello.view.php[[BR]]* a constructor and destructor function[[BR]]*and finally our index function to controll wht our Hello Application will do.||
    58 ||[[BR]]    public function index() {[[BR]]    ob_start();[[BR]]||||
    59 ||    $this->_view->hello();||'''The index function calls the hello function from the file hello.view.php''' ||
    60 ||[[BR]]     $str = ob_get_contents();[[BR]]       ob_end_clean();[[BR]]    $Page = PVars::getObj('page');[[BR]]    $Page->content .= $str;[[BR]]       }[[BR]]||The output for our Hello Application is written in the variable $str and the[[BR]] content from the rest of the BW page is added with the $Page variable||
    61 ||[[BR]]}[[BR]]?>||||
     36[[BR]]
    6237
    63 [[BR]]
    64 [[BR]]
    6538Finished! let`s test it!
    6639ah no, before we test it: the file build.xml needs to be changed aswell and should look like this: