Request example
Sizin böyle bir şey koyun index.php
:
<?php
// Holds data like $baseUrl etc.
include 'config.php';
$requestUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$requestString = substr($requestUrl, strlen($baseUrl));
$urlParams = explode('/', $requestString);
$controllerName = ucfirst(array_shift($urlParams)).'Controller';
$actionName = strtolower(array_shift($urlParams)).'Action';
// Here you should probably gather the rest as params
// Call the action
$controller = new $controllerName;
$controller->$actionName();
Gerçekten temel, ama fikir olsun ... (Ben de denetleyici sınıfını yükleme dikkat etmedi, ama ben o autoloading yoluyla ya da bunu yapmak için nasıl biliyor ya da yapılabilir sanırım.)
Simple controller example (kontrolörleri / login.php):
<?php
class LoginController
{
function loginAction()
{
$username = $this->request->get('username');
$password = $this->request->get('password');
$this->loadModel('users');
if ($this->users->validate($username, $password))
{
$userData = $this->users->fetch($username);
AuthStorage::save($username, $userData);
$this->redirect('secret_area');
}
else
{
$this->view->message = 'Invalid login';
$this->view->render('error');
}
}
function logoutAction()
{
if (AuthStorage::logged())
{
AuthStorage::remove();
$this->redirect('index');
}
else
{
$this->view->message = 'You are not logged in.';
$this->view->render('error');
}
}
}
Sözde uygulama mantığı - Gördüğünüz gibi, kontrolör uygulamanın "akış" ilgilenir. Bu veri depolama ve sunum hakkında dikkat etmez. Oldukça (şimdiki isteğine bağlı olarak) tüm gerekli verileri toplar ve görünümüne atar ...
Bu biliyorum herhangi bir çerçeve ile işe yaramaz, ama işlevleri yapmak gerekiyordu biliyorum eminim unutmayın.