Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^210) CHAPTER 14 ■ MVC ARCHITECTURE
public function getParams() {
return $this->_params;
}
public function getController() {
return $this->_controller;
}
public function getAction() {
return $this->_action;
}
public function getBody() {
return $this->_body;
}
public function setBody($body) {
$this->_body = $body;
}
}
The Controller
The controller is where you create your application code. It is just a normal class, except that it
implements the IController “marker” interface that does not contain any methods. Create the
IController interface as shown in Listing 14-5.
Listing 14-5. The IController Interface



pico –w application/models/icontroller.php
<?php
interface IController {}
Next, you will create a class to encapsulate your program logic. This class will be respon-
sible for creating an instance of the view (which you’ll define shortly), binding a variable to it,
and calling the render method, which will return the parsed result.
Once the view is rendered, the controller sets the body of the FrontController and returns.
Create this class as shown in Listing 14-6.
Listing 14-6. A Default Controller
pico –w application/controllers/index.php
<?php
McArthur_819-9C14.fm Page 210 Thursday, February 28, 2008 7:44 AM


Free download pdf