// User model uses database as storage
class Model_User extends Framework_Model_Database
{
$ _table = "users" ;
$ _pkey = "id" ;
function getByLogin ( $ login ) { /*...*/ }
function getByEmail ( $ email ) { /*...*/ }
}
// model MainConfig uses ini file as storage
class Model_MainConfig extends Framework_Model_Ini
{
protected $ _file = "application.ini" ;
function setOption ( $ key ) { /*...*/ }
function getOption ( $ key ) { /*...*/ }
}
// the Registry model uses memory as storage - some alternative to global variables
class Model_Registry extends Framework_Model_Memory
{
function setOption ( $ key ) { /*...*/ }
function getOption ( $ key ) { /*...*/ }
}
// Session model uses session files as storage
class Model_Session extends Framework_Model_Session
{
protected $ _namespace = "global" ;
function setOption ( $ key ) { /*...*/ }
function getOption ( $ key ) { /*...*/ }
}
In fact, with such examples I strongly distort the idea of ββMVC - in fact, often by model they mean some business model, but not a session or a configuration file.
<? php if ( $ this -> books ) : ?>
<! - A table of several books. ->
<table>
<tr>
<th> Author </ th>
<th> Title </ th>
</ tr>
<? php foreach ( $ this -> books as $ key => $ val ) : ?>
<tr>
<td> <? php echo $ this -> escape ( $ val [ 'author' ] ) ?> </ td>
<td> <? php echo $ this -> escape ( $ val [ 'title' ] ) ?> </ td>
</ tr>
<? php endforeach ; ?>
</ table>
<? php else : ?>
<p> There are no books to display. </ p>
<? php endif ; ?>
Oh yes, in the Zend Framework, the successful implementation of the presentation, I like it, of course, not without minor complaints, but in general it is five.
example.com/?controller=users&action=profile&id=16
// -
class Controller_Users extends Framework_Controller_Action
{
public function actionProfile()
{
//
$id = $this->request->get('id');
//
$user = new Model_User();
$user -> getById($id);
//
$this->view->user = $user;
}
}
Request'a β . β .
example.com/?controller=users&action=profile&id=16
example.com/users/profile/id/16 // URL'a ZF
example.com/users/profile/16 // CodeIgniter
example.com/profile/16 // ,
β URL , :example.com/users/list/page/2/limit/20/filter/active
example.com/users/list/2/20/active
Request, , URL View β Request β , , Request View
Response ZF β
Zend Framewrok' β , , .. Zend'a ( : ZYM)
«» β ...
project |-- application | |-- configs | |-- layouts | |-- controllers | |-- models | |-- views | `-- modules | `-- <module_name> | |-- layouts | |-- controllers | |-- models | `-- views |-- data | |-- cache | |-- logs | `-- sessions |-- library | `-- Framework |-- public | |-- styles | |-- scripts | |-- images | |-- uploads | |-- .htaccess | `-- index.php `-- tests
Source: https://habr.com/ru/post/68093/
All Articles