Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Zend Feed/Rss
Forum PHP.pl > Forum > Przedszkole
cykcykacz
CODE

An error occurred
Application error
Exception information:

Message: title key is missing
Stack trace:

#0 C:\wamp\www\zf_cms\library\Zend\Feed\Builder.php(182): Zend_Feed_Builder->_createEntries(Array)
#1 C:\wamp\www\zf_cms\library\Zend\Feed.php(392): Zend_Feed_Builder->__construct(Array)
#2 C:\wamp\www\zf_cms\application\controllers\FeedController.php(46): Zend_Feed::importArray(Array, 'rss')
#3 C:\wamp\www\zf_cms\library\Zend\Controller\Action.php(516): FeedController->rssAction()
#4 C:\wamp\www\zf_cms\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('rssAction')
#5 C:\wamp\www\zf_cms\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 C:\wamp\www\zf_cms\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 C:\wamp\www\zf_cms\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 C:\wamp\www\zf_cms\public\index.php(26): Zend_Application->run()
#9 {main}


  1. public function rssAction()
  2. {
  3. // action body
  4. // build the feed array
  5. $feedArray = array();
  6. // the title and link are required
  7. $feedArray['title'] = 'Recent Pages';
  8. $feedArray['link'] = 'http://localhost';
  9. // the published timestamp is optional
  10. $feedArray['published'] = Zend_Date::now()->toString(Zend_Date::TIMESTAMP);
  11. // the charset is required
  12. $feedArray['charset'] = 'UTF8';
  13. // first get the most recent pages
  14. $mdlPage = new Model_Page();
  15. $recentPages = $mdlPage->getRecentPages();
  16. //add the entries
  17. if(is_array($recentPages) && count($recentPages) > 0) {
  18. foreach ($recentPages as $page) {
  19. // create the entry
  20. $entry = array();
  21. $entry['guid'] = $page->id;
  22. $entry['title'] = $page->headline;
  23. $entry['link'] = 'http://localhost/page/open/title/' . $page->name;
  24. $entry['description'] = $page->description;
  25. $entry['content'] = $page->content;
  26. // add it to the feed
  27. $feedArray['entries'][] = $entry;
  28. }
  29. }
  30. // create an RSS feed from the array
  31. $feed = Zend_Feed::importArray($feedArray, 'rss');
  32. // now send the feed
  33. $this->_helper->viewRenderer->setNoRender();
  34. $this->_helper->layout->disableLayout();
  35. $feed->send();
  36. }


Nie wiem dlaczego dostaję error?
skowron-line
Zobacz czy zmienna
Kod
$page->headline

nie jest pusta.
cykcykacz
No właśnie z tą zmienną mam problem!

Poza tym właśnie korzystam z książki Pro Zend Framework Techniques. I stwierdziłem, że coś jest namieszane.

Tak wyglądają tabele do których się odwołuje.
http://imageshack.us/photo/my-images/198/skrin1.png/
http://imageshack.us/photo/my-images/42/skrin2.png/

A tak wygląda kod który pobiera zapisuje... z bazy danych.

  1. <?php
  2.  
  3. class Model_Page extends Zend_Db_Table_Abstract
  4. {
  5. /**
  6.   * The default table name
  7.   */
  8. protected $_name = 'pages';
  9. protected $_dependentTables = array('Model_ContentNode');
  10. protected $_referenceMap = array('Page' => array('columns' => array('parent_id') , 'refTableClass' => 'Model_Page' , 'refColumns' => array('id') , 'onDelete' => self::CASCADE , 'onUpdate' => self::RESTRICT));
  11. public function createPage ($name, $namespace, $parentId = 0)
  12. {
  13. //create the new page
  14. $row = $this->createRow();
  15. $row->name = $name;
  16. $row->namespace = $namespace;
  17. $row->parent_id = $parentId;
  18. $row->date_created = time();
  19. $row->save();
  20. // now fetch the id of the row you just created and return it
  21. $id = $this->_db->lastInsertId();
  22. return $id;
  23. }
  24. public function updatePage ($id, $data)
  25. {
  26. // find the page
  27. $row = $this->find($id)->current();
  28. if ($row) {
  29. // clear any cache records which are tagged to this page
  30. $cache = Zend_Registry::get('cache');
  31. $tag = 'page_' . $id;
  32. $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array($tag));
  33. // update each of the columns that are stored in the pages table
  34. $row->name = $data['name'];
  35. $row->parent_id = $data['parent_id'];
  36. $row->save();
  37. // unset each of the fields that are set in the pages table
  38. unset($data['id']);
  39. unset($data['name']);
  40. unset($data['parent_id']);
  41. // set each of the other fields in the content nodes table
  42. if (count($data) > 0) {
  43. $mdlContentNode = new Model_ContentNode();
  44. foreach ($data as $key => $value) {
  45. $mdlContentNode->setNode($id, $key, $value);
  46. }
  47. }
  48. } else {
  49. throw new Zend_Exception('Could not open page to update!');
  50. }
  51. }
  52. public function deletePage ($id)
  53. {
  54. // find the row that matches the id
  55. $row = $this->find($id)->current();
  56. if ($row) {
  57. $row->delete();
  58. return true;
  59. } else {
  60. throw new Zend_Exception("Delete function failed; could not find page!");
  61. }
  62. }
  63. public function getRecentPages ($count = 10, $namespace = 'page')
  64. {
  65. $select = $this->select();
  66. $select->order = 'date_created DESC';
  67. $select->where('namespace = ?', $namespace);
  68. $select->limit($count);
  69. $results = $this->fetchAll($select);
  70. if ($results->count() > 0) {
  71. //cycle through the results, opening each page
  72. $pages = array();
  73. foreach ($results as $result) {
  74. $pages[$result->id] = new CMS_Content_Item_Page($result->id);
  75. }
  76. return $pages;
  77. } else {
  78. return null;
  79. }
  80. }
  81. }
  82.  


  1. <?php
  2.  
  3. class Model_ContentNode extends Zend_Db_Table_Abstract {
  4.  
  5. /**
  6.   * The default table name
  7.   */
  8. protected $_name = 'content_nodes';
  9. protected $_referenceMap = array(
  10. 'Page' => array(
  11. 'columns' => array('page_id') ,
  12. 'refTableClass' => 'Model_Page' ,
  13. 'refColumns' => array('id') ,
  14. 'onDelete' => self::CASCADE ,
  15. 'onUpdate' => self::RESTRICT)
  16. );
  17. public function setNode ($pageId, $node, $value)
  18. {
  19. // fetch the row if it exists
  20. $select = $this->select();
  21. $select->where("page_id = ?", $pageId);
  22. $select->where("node = ?", $node);
  23. $row = $this->fetchRow($select);
  24. //if it does not then create it
  25. if (! $row) {
  26. $row = $this->createRow();
  27. $row->page_id = $pageId;
  28. $row->node = $node;
  29. }
  30. //set the content
  31. $row->content = $value;
  32. $row->save();
  33. }
  34.  
  35. }
  36.  
  37. ?>


  1. <?php
  2.  
  3. class CMS_Content_Item_Page extends CMS_Content_Item_Abstract
  4. {
  5. public $id;
  6. public $name;
  7. public $headline;
  8. public $image;
  9. public $description;
  10. public $content;
  11. }
  12.  
  13. ?>


  1. <?php
  2. abstract class CMS_Content_Item_Abstract
  3. {
  4. public $id;
  5. public $name;
  6. public $parent_id = 0;
  7. protected $_namespace = 'page';
  8. protected $_pageModel;
  9. const NO_SETTER = 'setter method does not exist';
  10. public function __construct ($page = null)
  11. {
  12. $this->_pageModel = new Model_Page();
  13. if (null != $page) {
  14. $this->loadPageObject($page);
  15. }
  16. }
  17. public function loadPageObject ($page)
  18. {
  19. if (is_object($page) && $page instanceof Zend_Db_Table_Row) {
  20. $row = $page;
  21. $this->id = $row->id;
  22. } else {
  23. $this->id = intval($page);
  24. $row = $this->_getInnerRow();
  25. }
  26. if ($row) {
  27. if ($row->namespace != $this->_namespace) {
  28. throw new Zend_Exception('Unable to cast page type:' . $row->namespace . ' to type:' . $this->_namespace);
  29. }
  30. $this->name = $row->name;
  31. $this->parent_id = $row->parent_id;
  32. $contentNode = new Model_ContentNode();
  33. $nodes = $row->findDependentRowset($contentNode);
  34. if ($nodes) {
  35. $properties = $this->_getProperties();
  36. foreach ($nodes as $node) {
  37. $key = $node['node'];
  38. if (in_array($key, $properties)) {
  39. // try to call the setter method
  40. $value = $this->_callSetterMethod($key, $nodes);
  41. if ($value === self::NO_SETTER) {
  42. $value = $node['content'];
  43. }
  44. $this->$key = $value;
  45. }
  46. }
  47. }
  48. } else {
  49. throw new Zend_Exception("Unable to load content item");
  50. }
  51. }
  52. protected function _getInnerRow ($id = null)
  53. {
  54. if ($id == null) {
  55. $id = $this->id;
  56. }
  57. return $this->_pageModel->find($id)->current();
  58. }
  59. protected function _getProperties ()
  60. {
  61. $propertyArray = array();
  62. $class = new Zend_Reflection_Class($this);
  63. $properties = $class->getProperties();
  64. foreach ($properties as $property) {
  65. if ($property->isPublic()) {
  66. $propertyArray[] = $property->getName();
  67. }
  68. }
  69. return $propertyArray;
  70. }
  71. protected function _callSetterMethod ($property, $data)
  72. {
  73. //create the method name
  74. $method = Zend_Filter::filterStatic($property, 'Word_UnderscoreToCamelCase');
  75. $methodName = '_set' . $method;
  76. if (method_exists($this, $methodName)) {
  77. return $this->$methodName($data);
  78. } else {
  79. return self::NO_SETTER;
  80. }
  81. }
  82. public function toArray ()
  83. {
  84. $properties = $this->_getProperties();
  85. foreach ($properties as $property) {
  86. $array[$property] = $this->$property;
  87. }
  88. return $array;
  89. }
  90. public function save ()
  91. {
  92. if (isset($this->id)) {
  93. $this->_update();
  94. } else {
  95. $this->_insert();
  96. }
  97. }
  98. protected function _insert ()
  99. {
  100. $pageId = $this->_pageModel->createPage($this->name, $this->_namespace, $this->parent_id);
  101. $this->id = $pageId;
  102. $this->_update();
  103. }
  104. protected function _update ()
  105. {
  106. $data = $this->toArray();
  107. $this->_pageModel->updatePage($this->id, $data);
  108. }
  109. public function delete ()
  110. {
  111. if (isset($this->id)) {
  112. $this->_pageModel->deletePage($this->id);
  113. } else {
  114. throw new Zend_Exception('Unable to delete item; the item is empty!');
  115. }
  116. }
  117. }
  118. ?>
  119.  
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.