intro
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.
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
Please modify
This article uses the following spreadsheet.
application/bootstrap.php
with the following content.Please modify
yourBaseUrl
properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php 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_Db_Table_Abstract::setDefaultAdapter($dbAdapter); Zend_Controller_Front::run(APP_BASE . '/controllers'); |
This article uses the following spreadsheet.
1 2 3 4 |
No,Title,Description 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php require_once 'Zend/Form.php'; class GSheetForm extends Zend_Form { public function __construct() { parent::__construct(); $no = $this->createElement('text', 'no'); $no->setLabel('No') ->setRequired(true) ->addFilter('stringTrim') ->addValidator('int'); $title = $this->createElement('text', 'title'); $title->setLabel('Title') ->setRequired(true) ->addFilter('stringTrim') ->addValidator('stringLength', false, array(1,100)); $description = $this->createElement('text', 'description'); $description->setLabel('Description') ->setRequired(true) ->addFilter('stringTrim') ->addValidator('stringLength', false, array(1,200)); $this->addElements(array( $no, $title, $description )); } } |
3.Create Controller
Create the file
It extends
application/constorllers/GsheetsController.php
with the following content.It extends
My_Controller_Gsheets
created in the previous article.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php 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() { $this->_helper->redirector('logon'); } } |
4.Create Views
Create the file
Create the file
Create the file
Create the file
Create the file
application/views/scripts/gsheets/logon.phtml
with the following content.
1 2 3 4 5 6 7 8 9 10 11 |
<h1><?= $this->translate($this->name . '.title.logon') ?></h1> <?php if (isset($this->googleUri)) : ?> Go <a href="<?= $this->googleUri ?>">Google Logon Page</a> <?php else : ?> <ul> <li><a href="<?= $this->url(array('action'=>'list'))?>">list spreadsheet</a></li> </ul> <div> <a href="<?= $this->url(array('action'=>'logout'))?>">Logout</a> </div> <?php endif; ?> |
Create the file
application/views/scripts/gsheets/list.phtml
with the following content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<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) : ?> <table> <tr> <?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> </tr> <?php $row_id = 1; ?> <?php foreach($this->list->entries as $entry) : ?> <tr> <?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> </tr> <?php $row_id++; ?> <?php endforeach; ?> </table> <?php endif; ?> <div> <a href="<?= $this->url(array('action'=>'index'))?>">Back</a> </div> |
Create the file
application/views/scripts/gsheets/detail.phtml
with the following content.
1 2 3 4 5 6 7 8 9 10 11 12 |
<h1><?= $this->translate($this->name . '.title.detail') ?></h1> <?php if ($this->values) : ?> <dl> <?php foreach($this->values as $key => $value) : ?> <dt><?= $this->translate($key) ?></dt> <dd><?= $this->escape($value) ?></dd> <?php endforeach; ?> </dl> <?php endif; ?> <?php if ($this->form) : ?> <?= $this->form ?> <?php endif; ?> |
Create the file
application/views/scripts/gsheets/form.phtml
with the following content.
1 2 |
<h1><?= $this->translate($this->name . '.title.' . $this->action) ?></h1> <?= $this->form ?> |
Create the file
application/views/scripts/gsheets/finish.phtml
with the following content.
1 2 3 |
<h1><?= $this->translate($this->name . '.title.finish.' . $this->action) ?></h1> <a href="<?=$this->url(array('action'=>'list'))?>"> <?= $this->translate('back') ?></a> |
5.Check
Access the web server and check add/update/delete/view screens that uses google spreadsheet.
History
Date | Content |
---|---|
2008/5/8 | Published |