1. Go to this page and download the library: Download morket/hmvc-bundle 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/ */
php
namespace Acme\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Morket\Bundle\HMVCBundle\Controller\HMVC;
class ProductsController extends Controller
{
use HMVC;
public function getProductsAction()
{
try {
$user = $this->call('get_user', ['id' => $this->getRequest()->get('user_id')]);
// do something
} catch (NotFoundHttpException $e) {
// user not found
}
}
}
php
namespace Acme\Controller;
use Acme\Entity\User;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Request\ParamFetcher;
use Morket\Bundle\HMVCBundle\Controller\RadRestController;
use Symfony\Component\HttpKernel\Exception\HttpException;
class UsersController extends RadRestController
{
/**
* @View
*/
public function getUserAction($id)
{
return array('user' => $this->findOr404('App:User', ['id' => $id]));
}
/**
* @QueryParam(name="filter", mething($something);
$this->persist($user, true);
return $this->routeRedirectView('get_user', ['id' => $user->getId()], 201);
}
/**
* @View
*/
public function putUserAction($id)
{
$user = $this->call('get_user', ['id' => $id]);
$user->setUsername($this->getRequest()->get('username'));
$user->setSomething($this->getRequest()->get('something'));
$this->persist($user, true);
return $this->routeRedirectView('get_user', ['id' => $user->getId()], 200);
}
/**
* @View
*/
public function deleteUserAction($id)
{
throw new HttpException(500);
}
}
php
namespace Acme\Controller;
use Morket\Bundle\HMVCBundle\Controller\HMVC;
class InsaneController
{
use HMVC;
public function insaneAction()
{
$user = $this->call('get_user', ['id' => 1]); // get a user
$users = $this->call('get_users', [], [], ['filter' => 'mor']); // get users by filter
$this->call('post_users', ['username' => 'morket', 'something' => 'abc']); // add a user
$this->call('put_user', ['id' => 1], ['username' => 'morket', 'something' => 'cba']); // update user
$this->call('delete_user', ['id' => 1]); // delete user
}
}
php
namespace Acme\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ProductsController extends Controller
{
public function getProductsAction()
{
try {
$user = $this->get('morket_hmvc.agent')
->call('get_user', ['id' => $this->getRequest()->get('user_id')]);
// do something
} catch (NotFoundHttpException $e) {
// user not found
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.