views:

36

answers:

2

Hi guys, Still trying to learn the basics of MVC.

I'm making use of Zend_Loader for Google Calendar feed. What file would this information go in? The .phtml view?

// load library

    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Calendar');
    Zend_Loader::loadClass('Zend_Http_Client');

    // create authenticated HTTP client for Calendar service
    $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
    $user = "xxxxxxxxxxxx";
    $pass = "xxxxxxxxxxxx";
    $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
    $gcal = new Zend_Gdata_Calendar($client);

    $query = $gcal->newEventQuery();

    $query->setUser('xxxxxxxxxxxx');
  $secondary=true;
    $query->setVisibility('private');
    $query->setProjection('basic');
    $query->setOrderby('starttime');
    $query->setSortOrder('ascending');
    //$query->setFutureevents('true');

    $startDate=date('Y-m-d h:i:s');
    $endDate="2015-12-31";
    $query->setStartMin($startDate);
    $query->setStartMax($endDate);
    $query->setMaxResults(30);
    try {
      $feed = $gcal->getCalendarEventFeed($query);
    } catch (Zend_Gdata_App_Exception $e) {
      echo "Error: " . $e->getResponse();
    }

Thanks!

+1  A: 

This would go in a Zend Controller and the rendering would go in the view script.

Matt S
Thanks. I'm real new to ZF. Can you give me an example of how I would put this in my controller if this was example.phtml? I've got the public function exampleAction() in the controller but I don't know how to link them
Joel
The way MVC works (and ZF is an MVC framework) is it flows from controller to view automagically. The exampleAction() is the entry point (this is where your code can start executing and doing things) for logic. Once your action has completed (baring any redirects or interrupts) the framework will automatically load the view script (example.phtml in this case). The view script is used to render the HTML based on the data loaded during the controller execution. The purpose is to separate logic from view.
Matt S
Continue: You put all the above code related to the specific action inside exampleAction() setting view variables throughout and then during the example.phtml (view script) you render HTML based on these variables. A controller should not contain echo's but instead should set error variables that the view then displays correctly. This of course is a generalization and can be much more complex. If you haven't already I would suggest reading http://framework.zend.com/manual/en/learning.quickstart.intro.html it gives a good introduction to the MVC style.
Matt S
@matt I understand the concepts, but my biggest hurdle is actually figuring out how the code is supposed to look. I've gone through the QuickStart and some ZF tutorials, but I haven't been able to figure out specifically how this code I posted here will look in the exampleAction() method. Simple drag and drop doesn't seem to work-specifically how should that authentication section look? Once I see a little, I should (hopefully) be able to figure out the rest.
Joel
A: 

I'd create separate calendar service for all calendar tasks, configuration etc. then used it in the Controllers, and passed data to the View.

takeshin