public function fetchAll() { $resultSet = $this->getDbTable()->fetchAll(); $users = array(); //Zend_Debug::dump($resultSet);exit(); foreach ($resultSet as $row) { $user = new Model_ArticleModel(); $user->setId($row->id) ->setCat_id($row->cat_id) ->setUid($row->uid) ->setAname($row->aname) ->setDescription($row->description) ->setPrice($row->price) ->setFile_image($row->file_image) ->setPublished($row->published) ->setPackage($row->package) ->setTags($row->tags) ->setHighlighted($row->highlighted) ->setMapper($this); $users[] = $user; } return $users; } In my Model_ArticleModel all the properties are protected. I set up in my model this code public function toArray(){ $data = array(); foreach($this as $prop => $value){ if($prop == '_mapper'){ continue; } $key = $this->_strReplaceOnce($prop); $data[$key] = $value; } return $data; } protected function _strReplaceOnce($haystack){ $needle = '_'; $replace = ''; // Looks for the first occurence of $needle in $haystack // and replaces it with $replace. $pos = strpos($haystack, $needle); if ($pos === false) { // Nothing found return $haystack; } return substr_replace($haystack, $replace, $pos, strlen($needle)); } and it works fine. I peeped into Zend_View_Abstract and I saw if ('_' == substr($spec, 0, 1)) { require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception('Setting private or protected class members is not allowed', $this); } So I'm wondering if I'm making something wrong. All in all implement a toArray method is the only way to use a model in a PartialLoop so I don't see the reason for it imho. Bye. View this message in context: PartialLoop Model Zend_View_Abstract assign
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论