-
Notifications
You must be signed in to change notification settings - Fork 2
Using Objects
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.
- If you spot a typo or want to contribute an article, a how-to or a tip, please feel free to edit the Wiki directly
- If you you have any question or suggestion, please contact the phpManufaktur Support Group
© 2013 by phpManufaktur, kitFramework & kfHelloWorld are published under MIT license.