1. Go to this page and download the library: Download popphp/popphp 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/ */
$app = new Pop\Application(
$config, // An array, an array-like object or an instance of Pop\Config\Config
$autoloader, // An instance of Composer\Autoload\ClassLoader
$router, // An instance of Pop\Router\Router
$services, // An instance of Pop\Service\Locator
$events, // An instance of Pop\Event\Manager
$modules, // An instance of Pop\Module\Manager
);
use Pop\App;
$app = App::get(); // Returns the instance of the Pop\Application object
use Pop\App;
if (App::env('SOME_VALUE') == 'foo') {
// Do something
}
use Pop\App;
if (App::isLocal()) {
// Do something in the local environment
} else if (App::isProduction()) {
// Do something in the production environment
}
use Pop\App;
if (App::isDown()) {
// Handle the app in "maintenance mode"
}
namespace MyApp\Controller;
use Pop\Controller\AbstractController;
class IndexController extends AbstractController
{
// This is the default value
protected string $defaultAction = 'error';
// This is the default value
protected string $maintenanceAction = 'maintenance';
public function index()
{
// Do something for the index page
}
public function users()
{
// Do something for the users page
}
public function edit($id)
{
// Edit user with $id
}
public function error()
{
// Handle a non-match route request
}
public function maintenance()
{
// Handle requests that come in while the application is in maintenance mode
}
}
namespace MyApp\Table;
use Pop\Db\Record;
class Users extends Record
{
}
namespace MyApp\Model;
use Pop\Model\AbstractModel;
class User extends AbstractDataModel
{
}
use MyApp\Model\User;
$user = User::createNew($userData);
use MyApp\Model\User;
$userModel = new User();
$user = $userModel->update(1, $userData);
use MyApp\Model\User;
$userModel = new User();
$userModel->delete(1);
$userModel->remove([2, 3, 4]);
use MyApp\Model\User;
$users = User::fetchAll();
$user = User::fetch(1);
use MyApp\Model\User;
$users = User::filter('username LIKE myuser%')->getAll('-id', '10', 2);
// Using Composer's autoloader
$autoloader = lude __DIR__ . '/config/app.php');
// $myModuleConfig contains the config settings for the
// module, such as the autoload prefix and the routes
$app->register(new MyModule($myModuleConfig));
$app->on('app.route.pre', function($application) {
// Do some pre-route stuff
});
$app->setService('foo', 'MyApp\FooService');
namespace MyApp\Controller;
use Pop\Controller\AbstractController;
class IndexController extends AbstractController
{
public function index()
{
$foo = $this->application->services['foo'];
// Do something with the 'foo' service
}
}
namespace MyApp\Controller;
use Pop\Service\Container;
use Pop\Controller\AbstractController;
class IndexController extends AbstractController
{
public function index()
{
// 'default' is the default service container. Other service containers may be available.
$foo = Container::get('default')->get('foo');
// Do something with the 'foo' service
}
}