Difference between revisions of "Web Frameworks - Workbook - Week 07"

From mi-linux
Jump to navigationJump to search
Line 16: Line 16:
  
 
== Create a new controller and view ==
 
== Create a new controller and view ==
 +
 +
First, run the following line of command:
  
 
<pre>
 
<pre>
 
zf.sh create controller simpy
 
zf.sh create controller simpy
 
</pre>
 
</pre>
 +
 +
A new "simpy" controller and martching view will be created.
 +
 +
== The controller ==
 +
 +
<pre>
 +
<?php
 +
 +
// application/controllers/SimpyController.php
 +
 +
class SimpyController extends Zend_Controller_Action
 +
{
 +
    public function indexAction()
 +
    {
 +
      // Here we set up the account username and password.
 +
      // Go to www.simpy.com and sign up for an account, it's free!
 +
      $user = "YOUR OWN SIMPY USER NAME";
 +
      $pass = "YOUR OWN SIMPY PASSWORD";
 +
     
 +
      // Create a new instance of the simpy object, using our username and password.
 +
      $simpy = new Zend_Service_Simpy($user, $pass);
 +
     
 +
      /* Search for the 20 links added most recently */
 +
      $linkQuery = new Zend_Service_Simpy_LinkQuery();
 +
      $linkQuery->setLimit(20);
 +
     
 +
      /* Pass results to view */
 +
      $linkSet = $simpy->getLinks($linkQuery);
 +
      $this->view->entries = $linkSet;
 +
     
 +
      /* Next, search for the 5 links added most recently tagged with 'Radiohead' */
 +
      $linkQuery->setQueryString('tags:Radiohead');
 +
      $linkQuery->setLimit(5);
 +
     
 +
      /* Pass results to view */
 +
      $linkSet = $simpy->getLinks($linkQuery);
 +
      $this->view->entries_tag = $linkSet;
 +
     
 +
    }
 +
}
 +
</pre>
 +
 +
== The view ==

Revision as of 13:10, 2 February 2010

Main Page >> Web Frameworks >> Workbook >> Workshop - week 07

Zend provides many classes to access a variety of APIs via its collection of Zend_Service classes.

Today let's have a look at the Zend_Service_Simpy class.

Zend_Service_Simpy

Simpy is a social bookmarking service. With Simpy, you can save, tag and search your own bookmarks and notes or browse and search other users' links and tags. You can be open and share your links with others, or keep them private.

Simpy also helps you find like-minded people, discover new and interesting sites, publish your bookmarks, detect and eliminate link-rot, etc.

So before you start, create an account, it's free!

Now, let's see how you can display your favourite websites on your Zend application.

Create a new controller and view

First, run the following line of command:

zf.sh create controller simpy

A new "simpy" controller and martching view will be created.

The controller

<?php

// application/controllers/SimpyController.php

class SimpyController extends Zend_Controller_Action
{
    public function indexAction()
    {
      // Here we set up the account username and password. 
      // Go to www.simpy.com and sign up for an account, it's free!
      $user = "YOUR OWN SIMPY USER NAME";
      $pass = "YOUR OWN SIMPY PASSWORD"; 
       
      // Create a new instance of the simpy object, using our username and password.
      $simpy = new Zend_Service_Simpy($user, $pass);
       
      /* Search for the 20 links added most recently */
      $linkQuery = new Zend_Service_Simpy_LinkQuery();
      $linkQuery->setLimit(20);
       
      /* Pass results to view */
      $linkSet = $simpy->getLinks($linkQuery);
      $this->view->entries = $linkSet;
      
      /* Next, search for the 5 links added most recently tagged with 'Radiohead' */
      $linkQuery->setQueryString('tags:Radiohead');
      $linkQuery->setLimit(5);
       
      /* Pass results to view */
      $linkSet = $simpy->getLinks($linkQuery);
      $this->view->entries_tag = $linkSet;
      
    }
}

The view