PHP code example of codermarcel / simple-controller

1. Go to this page and download the library: Download codermarcel/simple-controller 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/ */

    

codermarcel / simple-controller example snippets


use Codermarcel\SimpleController\SimpleController;;

class MyExampleControllerExtended extends SimpleController
{
	/**
	 * Responds to requests to GET /
	 */
	public function getIndex()
	{
		return echo 'Welcome!';
	}
}

$app->mount('/', new App\Controllers\MyExampleControllerExtended());

class MyExampleControllerRaw
{
	/**
	 * Responds to requests to GET /
	 */
	public function getIndex()
	{
		return echo 'Welcome!';
	}
}

$app->mount('/', new Codermarcel\SimpleController\SimpleController('App\Controllers\MyExampleControllerRaw'));

class MyExampleControllerRaw
{
    /**
     * Responds to requests to GET /test
     */
    public function getTest()
    {
        //
    }

    /**
     * Responds to requests to GET /show/{id}
     */
    public function getShow($id)
    {
        //
    }

    /**
     * Responds to requests to GET /admin-profile
     */
    public function getAdminProfile()
    {
		//
    }

    /**
     * Responds to requests to POST /profile
     */
    public function postProfile()
    {
		//
    }

}

$app->mount('/', new App\Controllers\MyExampleControllerExtended());

use Codermarcel\SimpleController\SimpleController;;

class MyExampleControllerExtended extends SimpleController
{
	/**
	 * Responds to request to GET /
	 */
	public function getIndex()
	{
		//
	}

	/**
	 * Responds to request to GET /login-page
	 */
	public function getLoginPage()
	{
		//
	}
}

$app->mount('/user', new App\Controllers\MyExampleControllerExtended());

use Codermarcel\SimpleController\SimpleController;;

class MyExampleControllerExtended extends SimpleController
{
	/**
	 * Responds to request to GET /user/
	 */
	public function getIndex()
	{
		//
	}

	/**
	 * Responds to request to GET /user/home-page
	 */
	public function getHomePage()
	{
		//
	}
}

class MyExampleControllerRaw
{
	/**
	 * Responds to requests to POST /login{username}/{password}
	 */
	public function postLogin($username, $password)
	{
		return sprintf('Trying to log in with username: %s and password: %s', $username, $password);
	}
}

class MyExampleControllerRaw
{
	use Silex\Application;
	use Symfony\Component\HttpFoundation\Request;

	/**
	 * Responds to requests to GET /injection
	 */
	public function getInjection(Application $app, Request $request)
	{
		//
	}
}

class MyExampleControllerRaw
{
	use Silex\Application;
	use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

	/**
	 * Responds to requests to GET /bind-example
	 *
	 * {@link http://silex.sensiolabs.org/doc/providers/url_generator.html#usage}
	 */
	public function getBindExample(Application $app, $bind = 'bind_example')
	{
		//Example usage of the bind_example route
		//You can use ABSOLUTE_URL or ABSOLUTE_PATH
		return new Response($app['url_generator']->generate('bind_example', array(), UrlGeneratorInterface::ABSOLUTE_PATH));
	}
}

class MyExampleControllerRaw
{
	use Symfony\Component\HttpFoundation\Response;
	use Symfony\Component\HttpFoundation\Request;

	/**
	 * Before middleware example
	 *
	 * {@link http://silex.sensiolabs.org/doc/middlewares.html#before-middleware}
	 */
	public function beforeMiddleware(Request $request)
	{
		if ($request->getRequestUri() === '/before-middleware')
		{
			return new Response('YOU SHALL NOT PASS');
		}
	}

	/**
	 * After middleware example
	 *
	 * {@link http://silex.sensiolabs.org/doc/middlewares.html#after-middleware}
	 */
	public function afterSomeRandomNameThatDoesntMatter(Request $request, Response $response, Application $app)
	{
		if ($request->getRequestUri() === '/after-middleware')
		{
			return new Response($response->getContent() . ' | after-middleware content');
		}
	}
}