Avoiding Fat Controller
因此,我使用Zentd Framework,我有一个问题,涉及防止心脏控制器采取我的行动。 基本上,我正在将CSV档案整理成我的数据库。
This means that I have to get the feed and then use my model. The feed grabbing is just there to show how it works, but that is now an Action Helper.
我正在使用Zentd Framework的数据绘图仪。 我是在我的主计长中这样做的。 所有这一切都令人难以置信,我感到,在错误的地方这样做了吗? 如果我通过整个<$-feed,然后在这个类别中,我即时宣读我的模型和我的地图,那就是一个更好的选择?
此外,我需要实现正常化,这意味着我应该利用交易,但我不敢在我开始交易的时候这样做。 由于我目前的工作方式,我可以考虑的唯一地点是我的主计长。
How can I get the model behaviour and operations out of my controller?
<><>ImportController.php>
public function indexAction() {
$start = $this->getRequest()->getParam( start );
$end = $this->getRequest()->getParam( end );
$url = "http://www.domain.com/admin/GetBookingData.aspx";
$client = new Zend_Http_Client();
$client->setParameterGet( dateEnteredMin , $start);
$client->setParameterGet( dateEnteredMax , $end);
$client->setParameterGet( login , login );
$client->setParameterGet( password , password );
$client->setUri( $url );
$client->setConfig(array(
maxredirects => 0,
timeout => 30));
// Send the request.
$response = $client->request();
// Grab the feed from ->getBody and add it to $feed
$feed = $this->csv_to_array(trim($response->getBody()));
// The first item in the array is the heading in the CSV, so we can remove it from the array using shift().
$title = array_shift($feed);
// Create my Models and Mappers.
// *** EVERYTHING BELOW HERE IS WHAT I DON T LIKE ***
$bookings = new Bookings_Models_Bookings();
$property = new Bookings_Models_Property();
$clients = new Bookings_Models_Clients();
$bookingsMapper = new Bookings_Models_Bookings_Mapper();
$propertyMapper = new Bookings_Models_Property_Mapper();
$clientsMapper = new Bookings_Models_Clients_Mapper();
$bookings->setId($feed[9])
->setPropertyId($feed[1])
->setClientId($feed[2])
->setDate($feed[4]);
$bookingsMapper->save($bookings);
$property->setId($feed[1])
->setPropertyName($feed[23])
$propertyMapper->save($bookings);
$clients->setId($feed[2])
->setFirstName($feed[20])
->setLastName($feed[21])
$clientsMapper->save($clients);
}