Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I call the methods in a model via controller? Zend Framework
    text
    copied!<p>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.</p> <p>First, I'm quite new to the MVC structure, though I have been doing tutorials and learning as best I can.</p> <p>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.</p> <p>So therefore I'm using one IndexController and I have the code in each Action method for each page: IE <code>public function exampleAction()</code> </p> <p>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).</p> <p>So basically, I had a working site by using a View and Controller and no model.</p> <p>...</p> <p>Now I'm trying to learn how to incorporate the Model.</p> <p>So I created a View at:</p> <pre><code>view/scripts/calendar/index.phtml </code></pre> <p>I created a new Controller at:</p> <pre><code>controller/CalendarControllers.php </code></pre> <p>and a new model at:</p> <pre><code>model/Calendar.php </code></pre> <p>The problem is I think I'm not correctly communication with the model (I'm still new to OOP).</p> <p>Can you look over my controller and model and tell me if you see a problem.</p> <p>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?</p> <p>Thanks for any help! I'm stripping out most of the guts of the methods for the sake of brevity:</p> <p>controller:</p> <pre><code>&lt;?php class CalendarController extends Zend_Controller_Action { public function indexAction() { $finishedFeedArray = new Application_Model_Calendar(); $this-&gt;view-&gt;googleArray = $finishedFeedArray; } } </code></pre> <p>model:</p> <pre><code> &lt;?php class Application_Model_Calendar { public function _runCalendarScript(){ $gcal = $this-&gt;_validateCalendarConnection(); $uncleanedFeedArray = $this-&gt;_getCalendarFeed($gcal); $finishedFeedArray = $this-&gt;_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-&gt;_cleanupText($event); $eventData = $this-&gt;_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; } } </code></pre> <p>Edit: sorry-I don't know why my formatting on the code keeps looking so ugly...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload