How do I call the methods in a model via controller? Zend Framework

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2010-06-07T03:00:28Z Indexed on 2010/06/07 3:02 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

Hi guys, I've been searching for tutorials to better understand this, but I'm having no luck. Please forgive the lengthy explination, but I want make sure I explain myself well.

First, I'm quite new to the MVC structure, though I have been doing tutorials and learning as best I can.

I have been moving over a live site into the Zend Framework model. So far, I have all the views within views/scripts/index/example.phtml.

So therefore I'm using one IndexController and I have the code in each Action method for each page: IE public function exampleAction()

Because I didn't know how to interact with a model, I put all the methods at the bottom of the controller (a fat controller).

So basically, I had a working site by using a View and Controller and no model.

...

Now I'm trying to learn how to incorporate the Model.

So I created a View at:

view/scripts/calendar/index.phtml

I created a new Controller at:

controller/CalendarControllers.php

and a new model at:

model/Calendar.php

The problem is I think I'm not correctly communication with the model (I'm still new to OOP).

Can you look over my controller and model and tell me if you see a problem.

I'm needing to return an array from runCalendarScript(), but I'm not sure if I can return an array into the object like I'm trying to? I don't really understand how to "run" the runCalendarScript() from the controller?

Thanks for any help! I'm stripping out most of the guts of the methods for the sake of brevity:

controller:

<?php

class CalendarController extends Zend_Controller_Action
{

    public function indexAction()
    {
        $finishedFeedArray = new Application_Model_Calendar();  

    $this->view->googleArray = $finishedFeedArray;
    }
}

model:

<?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;
}
}

© Stack Overflow or respective owner

Related posts about php

Related posts about oop