【发布时间】:2010-06-07 03:00:28
【问题描述】:
我一直在寻找教程以更好地理解这一点,但我没有运气。请原谅冗长的解释,但我想确保我解释清楚。
首先,我对 MVC 结构还是很陌生,尽管我一直在尽我所能做教程和学习。
我一直在将一个实时站点转移到 Zend 框架模型中。到目前为止,我拥有views/scripts/index/example.phtml中的所有视图。
因此,我使用了一个 IndexController,并且每个页面的每个 Action 方法中都有代码:IE public function exampleAction()
因为我不知道如何与模型交互,所以我把所有的方法都放在了控制器(胖控制器)的底部。
所以基本上,我有一个使用 View 和 Controller 而没有模型的工作站点。
...
现在我正在尝试学习如何合并模型。
所以我在以下位置创建了一个视图:
view/scripts/calendar/index.phtml
我在以下位置创建了一个新控制器:
controller/CalendarControllers.php
还有一个新模型:
model/Calendar.php
问题是我认为我没有正确地与模型进行通信(我还是 OOP 的新手)。
您能否检查一下我的控制器和模型,如果您发现问题,请告诉我。
我需要从 runCalendarScript() 返回一个数组,但我不确定是否可以像我尝试的那样将一个数组返回到对象中?我真的不明白如何从控制器“运行”runCalendarScript()?
感谢您的帮助!为简洁起见,我去掉了这些方法的大部分内容:
控制器:
<?php
class CalendarController extends Zend_Controller_Action
{
public function indexAction()
{
$finishedFeedArray = new Application_Model_Calendar();
$this->view->googleArray = $finishedFeedArray;
}
}
型号:
<?php
class Application_Model_Calendar
{
public function _runCalendarScript(){
$gcal = $this->_validateCalendarConnection();
$uncleanedFeedArray = $this->_getCalendarFeed($gcal);
$finishedFeedArray = $this->_cleanFeed($uncleanedFeedArray);
return $finishedFeedArray;
}
//Validate Google Calendar connection
public function _validateCalendarConnection()
{
...
return $gcal;
}
//extracts googles calendar object into the $feed object
public function _getCalendarFeed($gcal)
{
...
return $feed;
}
//cleans the feed to just text, etc
protected function _cleanFeed($uncleanedFeedArray)
{
$contentText = $this->_cleanupText($event);
$eventData = $this->_filterEventDetails($contentText);
return $cleanedArray;
}
//Cleans up all formatting of text from Calendar feed
public function _cleanupText($event)
{
...
return $contentText;
}
//filterEventDetails
protected function _filterEventDetails($contentText)
{
...
return $data;
}
}
编辑:抱歉-我不知道为什么我的代码格式看起来如此丑陋...
【问题讨论】:
标签: php oop zend-framework model