PHP code example of codeeverything / planck-framework
1. Go to this page and download the library: Download codeeverything/planck-framework library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codeeverything / planck-framework example snippets
// src/App/Controller/HelloController.php
namespace Planck\App\Controller;
class HelloController {
public function hello() {
return 'hello, world';
}
}
// controller code
// inject the service labelled as "db" into this function
public function init($db) {
$this->db = $db;
}
// more controller code
//src/App/Listener/ExampleListener.php
namespace Planck\App\Listener;
use Planck\Core\Event\IEventListener;
class ExampleListener implements IEventListener {
public function attachedEvents() {
return [
'controller.beforeAction' => 'doSomething', // core Planck event, triggered before the controller function resolved from the route is called
'app.hello' => 'hello', // app specific event
];
}
public function doSomething($controller) {
$controller->set([
'externalListener' => true,
]);
}
public function hello($controller, $name) {
$controller->set([
"hello.message" => "Why hello $name! How you doin'? :)"
]);
}
}
// src/App/Controller/HelloController
use Planck\Core\Event\Event;
public function hello($name) {
echo "Hello, $name";
// emit an event and pass the current object plus some more stuff. you can pass anything you want here
Event::emit('app.welcomed', [$this, $moreData]);
}
// more goodness
$this->ok()
$this->created()
$this->created(false)
$this->blank()
$this->unchanged()
config/listeners.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.