Skip to content
hertsch edited this page Aug 7, 2013 · 4 revisions

If the controller process only some lines of code it is no problem to place them within the closure of the controller function.

You will get a better structured code and more flexibility if you are using objects within the controllers.

Please try

~~ HelloObject ~~

The kitCommand will return

Hello World, this is thirdParty\HelloWorld\Control\HelloObject::SayHello

HelloObject need at the top of the bootstrap.include.php of the HelloWorld extension a use statement:

use thirdParty\HelloWorld\Control\HelloObject;

the controller itself:

$app->post('/command/helloobject', function() {
    $HelloObject = new SayHello();
    return $HelloObject->SayHello();
});

and in the path

/extension/thirdparty/thirdParty/HelloWorld/Control/HelloObject.php

the small class HelloObject:

namespace thirdParty\HelloWorld\Control;

class HelloObject {
    
    /**
     * Return "Hello World" and the __METHOD__ name
     * 
     * @return string
     */
    public function SayHello()
    {
        return 'Hello World, this is '.__METHOD__;
    }
}

In such way you are independent and can create the things like you want.

The kitFramework provide you with a class Basic which give an easy access to the kitCommand control, in the next step we will use the class Basic.

Clone this wiki locally