witam
mam następujący problem a jako że eclipse mi do gustu przypadł i ładnie potrafi wszystko prawie (IMG:
style_emoticons/default/smile.gif) podpowiedzieć chciałbym się dowiedzieć czy da się osiągnąć taki efekt
używam Zend_Db ( dla mnie pasuje więc to najważniejsze ) a chcę osiągnąć aby eclipse potrafił rozpoznać ze w pętli (foreach) chcę po tablicy obiektów przechodzić i dla każdego elementu podpowiadał metody
nie wiem czy się da tak zrobić
klasa modelu danych
class Model extends Generate_Model{
/**
*
* @param int $limit
* @return Generate_Model
*/
public function getAll($limit=100) {
return $this->fetchList(NULL,NULL,$limit);
}
}
klasa wygenerowana modelu danych
<?php
class Generate_Model {
protected $_IDModel;
protected $_PolePierwsze;
protected $_PoleDrugie;
protected $_mapper;
function setIDModel($data) {
$this->_IDModel=$data;
return $this;
}
function getIDModel() {
return $this->_IDModel;
}
function setPolePierwsze($data) {
$this->_PolePierwsze=$data;
return $this;
}
function getPolePierwsze() {
return $this->_PolePierwsze;
}
function setPoleDrugie($data) {
$this->_PoleDrugie=$data;
return $this;
}
function getPoleDrugie() {
return $this->_PoleDrugie;
}
function __call
($method, array $args){ /**
* Recognize methods for Belongs-To cases:
* findBy<field>()
* Use the non-greedy pattern repeat modifier e.g. \w+?
*/
if (preg_match('/^findBy(\w+)?$/', $method, $matches)){ $methods = get_class_methods($this);
$check = "set{$matches[1]}";
throw new Exception("Invalid field {$matches[1]} requested for table");
}
$this->getMapper()->findByField($matches[1], $args[0], $this);
return $this;
}
throw new Exception("Unrecognized method '$method()'");
}
public function __set($name, $value){
$method = "set$name";
if (("mapper" == $name) || !method_exists($this, $method)){
throw new Exception("name:$name value:$value - Invalid model property");
}
$this->$method($value);
}
public function __get($name){
$method = "get$name";
if (("mapper" == $name) || !method_exists($this, $method)){
throw new Exception("name:$name - Invalid model property");
}
return $this->$method();
}
public function setOptions
(array $options){ $methods = get_class_methods($this);
foreach ($options as $key => $value){
$key = preg_replace_callback("/_(.)/", create_function
('$matches','return ucfirst($matches[1]);'), $key); $this->$method($value);
}
}
return $this;
}
public function setMapper($mapper){
$this->_mapper = $mapper;
return $this;
}
public function getMapper(){
if (null === $this->_mapper){
$this->setMapper(new Generate_Mapper_Model());
}
return $this->_mapper;
}
public function save(){
$this->getMapper()->save($this);
}
public function find($id){
$this->getMapper()->find($id, $this);
return $this;
}
public function fetchAll(){
return $this->getMapper()->fetchAll();
}
public function fetchList($where=null, $order=null, $count=null, $offset=null){
return $this->getMapper()->fetchList($where, $order, $count, $offset);
}
}
klasa mapera jest tutaj do niczego nie potrzebna
a teraz kod i to co chce osiągnąć
Zend_Db_Table::setDefaultAdapter($db);
try{
$model = new model();
$result = $model->getAll();
// dla $result eclipse podpowiada wszytkie metody dostepowe ( setPolePierwsze, getPolePierwsze itp )
//choć jest to tablica obiektów
foreach ($result as $row) {
// a jak zrobić i czy sie da aby eclipse wiedział ze $row to obiekt Generate_Model
//$row->
}
}
catch (Exception $e){
}
czy da się to osiągnąć
generowanie modeli o odpowiednie komętarze phpDoc mogę spokojnie poprawic ale nie wiem o co, jak zrobić aby eclipse wiedział że będzie lista obieków zwrócona a w pętli już operacje na pojedynczym obiekcie