Home > Zend_Gdata > Implementing Add/Update/Delete/View Screens using Zend_Gdata_Spreadsheets

Implementing Add/Update/Delete/View Screens using Zend_Gdata_Spreadsheets

This article shows code that uses google spreadsheet CRUD controller created in previous article.
You can download the source code of this article from here.
You can check the screens from demonstration site.

1.Create bootstrap.php
Create the file application/bootstrap.php with the following content.
Please modify yourBaseUrl properly.

set_include_path('../library' . PATH_SEPARATOR . get_include_path());
define('APP_BASE', '../application');
define('CONFIG_PATH', APP_BASE . '/config.ini');
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Layout.php';
require_once 'Zend/Db.php';
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Db/Table/Abstract.php';
$layout = Zend_Layout::startMvc();
//$layout->getView()->baseUrl = '/yourBaseUrl';
$config = new Zend_Config_Ini(CONFIG_PATH, 'staging');
$params = $config->database->params->toArray();
$params['options'][Zend_Db::CASE_FOLDING] = Zend_Db::CASE_LOWER;
$dbAdapter = Zend_Db::factory($config->database->adapter, $params);
Zend_Controller_Front::run(APP_BASE . '/controllers');

This article uses the following spreadsheet.

1,Creating Google Spreadsheet,How to create documents
2,Reading Google Spreadsheet,How to read documents
3,Writing Google Spreadsheet,How to write documents
2.Create Model
Create the file application/models/form/GsheetForm.php with the following content.

require_once 'Zend/Form.php';
class GSheetForm extends Zend_Form
    public function __construct()
        $no = $this->createElement('text', 'no');
        $title = $this->createElement('text', 'title');
              ->addValidator('stringLength', false, array(1,100));
        $description = $this->createElement('text', 'description');
                    ->addValidator('stringLength', false, array(1,200));
            $no, $title, $description
3.Create Controller
Create the file application/constorllers/GsheetsController.php with the following content.
It extends My_Controller_Gsheets created in the previous article.

require_once 'My/Controller/Gsheets.php';
require_once APP_BASE . '/models/forms/GSheetForm.php';
class GsheetsController extends My_Controller_Gsheets
    protected $_session_name = "GSheets";
    protected $_table_class = null;
    protected $_form_class = "GSheetForm";
    protected $_spreadsheet_name = 'Test Spreadsheet';
    public function preDispatch()
        $this->view->name = "gsheets";
    public function indexAction()
4.Create Views
Create the file application/views/scripts/gsheets/logon.phtml with the following content.

<h1><?= $this->translate($this->name . '.title.logon') ?></h1>
<?php if (isset($this->googleUri)) : ?>
Go <a href="<?= $this->googleUri ?>">Google Logon Page</a>
<?php else : ?>
<li><a href="<?= $this->url(array('action'=>'list'))?>">list spreadsheet</a></li>
<a href="<?= $this->url(array('action'=>'logout'))?>">Logout</a>
<?php endif; ?>

Create the file application/views/scripts/gsheets/list.phtml with the following content.

<h1><?= $this->translate($this->name . '.title.list') ?></h1>
<a href="<?=$this->url(array('action'=>'add'))?>">
<?= $this->translate($this->name . '.label.new') ?></a>
<?php if ($this->list) : ?>
<?php   $headerData = $this->list->entries[1]->getCustom(); ?>
<?php   foreach($headerData as $customEntry) : ?>
<th><?= $customEntry->getColumnName() ?></th>
<?php   endforeach; ?>
<th><?= $this->translate('detail') ?></th>
<th><?= $this->translate('edit') ?></th>
<th><?= $this->translate('delete') ?></th>
<?php   $row_id = 1; ?>
<?php   foreach($this->list->entries as $entry) : ?>
<?php     $rowData = $entry->getCustom(); ?>
<?php     foreach($rowData as $customEntry) : ?>
<td><?= $customEntry->getText() ?></td>
<?php     endforeach; ?>
<td><a href="<?=$this->url(array('action'=>'detail'))?>?id=<?=$row_id?>">
  <?= $this->translate('detail') ?></a></td>
<td><a href="<?=$this->url(array('action'=>'update'))?>?id=<?=$row_id?>">
  <?= $this->translate('edit') ?></a></td>
<td><a href="<?=$this->url(array('action'=>'delete'))?>?id=<?=$row_id?>">
  <?= $this->translate('delete') ?></a></td>
<?php   $row_id++; ?>
<?php   endforeach; ?>
<?php endif; ?>
<a href="<?= $this->url(array('action'=>'index'))?>">Back</a>

Create the file application/views/scripts/gsheets/detail.phtml with the following content.

<h1><?= $this->translate($this->name . '.title.detail') ?></h1>
<?php if ($this->values) : ?>
<?php foreach($this->values as $key => $value) : ?>
<dt><?= $this->translate($key) ?></dt>
<dd><?= $this->escape($value) ?></dd>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($this->form) : ?>
<?= $this->form ?>
<?php endif; ?>

Create the file application/views/scripts/gsheets/form.phtml with the following content.

<h1><?= $this->translate($this->name . '.title.' . $this->action) ?></h1>
<?= $this->form ?>

Create the file application/views/scripts/gsheets/finish.phtml with the following content.

<h1><?= $this->translate($this->name . '.title.finish.' . $this->action) ?></h1>
<a href="<?=$this->url(array('action'=>'list'))?>">
<?= $this->translate('back') ?></a>

Access the web server and check add/update/delete/view screens that uses google spreadsheet.
Date Content
2008/5/8 Published


Comment Form
Remember personal info


Trackback URL for this entry
Listed below are links to weblogs that reference
Implementing Add/Update/Delete/View Screens using Zend_Gdata_Spreadsheets from Open Programming Laboratory

Home > Zend_Gdata > Implementing Add/Update/Delete/View Screens using Zend_Gdata_Spreadsheets


Return to page top