PHP code example of dkplus / action-arguments

1. Go to this page and download the library: Download dkplus/action-arguments 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/ */

    

dkplus / action-arguments example snippets


use DkplusActionArguments\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    /**
     * Route looks like /user/:id
     */
    public function viewAction($id)
    {
        return array('user' => $this->mapper->find($id));
    }
}

use DkplusActionArguments\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    /**
     * Route looks like /user/:user
     */
    public function viewAction(User $user)
    {
        return array('user' => $user);
    }
}

use DkplusActionArguments\Annotation\MapParam;
use DkplusActionArguments\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    /**
     * Route looks like /user/:name
     * @MapParam(from="name", to="user", using="findOneByName")
     */
    public function viewAction(User $user)
    {
        return array('user' => $user);
    }
}

use DkplusActionArguments\Annotation\MapParam;
use DkplusActionArguments\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    /**
     * Route looks like /user/:user
     * @MapParam(to="user", using={"sm_key", "method"})
     */
    public function viewAction(User $user)
    {
        return array('user' => $user);
    }
}

use DkplusActionArguments\Annotation\MapParam;
use DkplusActionArguments\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    /**
     * Route looks like /user/:user
     * @MapParam(to="user", using="my_converter_sm_key")
     */
    public function viewAction(User $user)
    {
        return array('user' => $user);
    }
}