Skip to content

Instantly share code, notes, and snippets.

@timothylhuillier
Forked from Anahkiasen/separated.php
Created May 28, 2013 21:48
Show Gist options
  • Save timothylhuillier/5666424 to your computer and use it in GitHub Desktop.
Save timothylhuillier/5666424 to your computer and use it in GitHub Desktop.
API or NOT API
<?php
//////////////////////////////////////////////////////////////////////
//////////////////////// METHODOLOGIE SEPARÉE ////////////////////////
//////////////////////////////////////////////////////////////////////
// app/controllers/UsersController --------------------------------- /
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return View::make('users.show')
->with('user', $user);
}
}
// app/controllers/Api/UsersController ----------------------------- /
namespace Api;
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return $user;
}
}
<?php
//////////////////////////////////////////////////////////////////////
//////////////////////// METHODOLOGIE UNIFIÉE ////////////////////////
//////////////////////////////////////////////////////////////////////
// app/controllers/UsersController --------------------------------- /
class UsersController
{
/**
* Instance of the Users API
*
* @var Api\UsersController
*/
protected $api;
public function __construct()
{
$this->api = new Api\UsersController;
}
public function getUser($id)
{
$user = $this->api->getUser($id);
return View::make('users.show')
->with('user', $user);
}
}
// app/controllers/Api/UsersController ----------------------------- /
namespace Api;
class UsersController
{
public function getUser($id)
{
$user = User::findOrFail($id);
return $user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment