안녕 난 (하지만이 부적절하다고 생각)와 PHP5 난 그냥 내가 여기서 뭘하는지 개체 기본적으로PHP 객체 전달 객체 : 참조 또는 값?
public function saveSite($post) {
$form = new Diff_Form_Download();
$subform = new Diff_Form_DownloadSubform();
$form = $this->view->form;
$newSite = 0;
$sitesRecord = new Diff_Model_Sites();
$debugString = null;
if (is_array($post)) {
$subform = $this->getSubformByPost($post);
$debugString = $subform->getContent();
echo $debugString;
//new site instertion
if (is_null($subform)) {
$subform = $form->getSubForm('NewSite');
$newSite = 1;
}
$values = reset($subform->getValues());
$sitesRecord = Doctrine_Core::getTable('Diff_Model_Sites')->findOneBy('idSite', $values['idSite']);
if ($sitesRecord) {
$sitesRecord->idSite = $values['idSite']; //useless but necessary to make Doctrine understand to use update?
} else { //if the record is not present instantiate a new object (otherwise save() will not work
$sitesRecord = new Diff_Model_Sites();
}
$sitesRecord->content = $subform->getContent(); //$values['content'];
$sitesRecord->newHtml = $subform->getContent();
$sitesRecord->url = $values['url'];
$sitesRecord->shortName = $values['shortName'];
$sitesRecord->lastChanged = date("Y-m-d H:i:s");
$sitesRecord->pollingHours = $values['pollingHours'];
$sitesRecord->minLengthChange = $values['minLenghtChange'];
if (Zend_Auth::getInstance()->hasIdentity()) { //save the owner
$sitesRecord->idOwner = Zend_Auth::getInstance()->getIdentity()->idOwner; //retrieve the owner
$sitesRecord->save();
} else {
throw new Exception("your session have expired: \n please login again");
}
}
}
/**
* return the calling subform
* @param type $post
* @return type
*/
public function getSubformByPost($post) {
$form = new Diff_Form_Download();
$form = $this->view->form;
$subform = new Diff_Form_DownloadSubform();
$subformName = "site" . $post['idSite'];
$subform = $form->getSubForm($subformName);
return $subform;
}
public function refreshOneDiff($post) {
$debugString;
if (is_array($post)) {
$form = new Diff_Form_Download();
$form = $this->view->form;
$subform = new Diff_Form_DownloadSubform();
$subform = $this->getSubformByPost($post);
if (!$subform)
$subform = $this->view->form->getSubformByPost('NewSite');
$url = $subform->getUrl();
$idSite = $subform->getIdSite();
$crawler = new Crawler();
$newpageContent = $crawler->get_web_page($url);
$siteRecord = new Diff_Model_Sites();
$siteRecord = $subform->getSiteRecord();
if ($siteRecord) //check if the record is not null
$oldpageContent = $siteRecord->get('content');
else
$oldpageContent = null;
$differences = $this->getDiff($oldpageContent, $newpageContent);
if (!is_null($differences)) {
$siteRecord->content = $newpageContent;
$subform->setContent($newpageContent);
$subform->setContentDiff($differences);
$subform->setSiteRecord($siteRecord);
$subform = $this->getSubformByPost($post);
$debugString = $subform->getContent();
}
//echo $debugString;
$sitePresence = Doctrine_Core::getTable('Diff_Model_Sites')->findOneBy('idSite', $idSite);
if ($sitePresence) {
//$this->saveSite($post);
$this->debugtry($post);
}
} else {
}
}
의 객체를 수정할 젠드 프레임 워크를 사용하고 모든입니다 1) 보기에서 양식을 잡으십시오 2) 양식에서 하위 양식 잡기 (SubformX라고 부름) 3) 서브폼에서 "siteRecordX"객체를 가져옵니다 4) "siteRecordX"값을 변경하십시오 5) saveRecord 함수를 호출하십시오() 6)이 함수에서 동일한 SubformX를 다시 계산하고 객체 siteRecordX의 값을 반향 출력
놀랍게도 SubformX의 변수를 변경하면 SubformX의 객체 변수를 변경하면 그대로 유지됩니다 (SubformX를 검색하는 경우). SubformX가 참조로 전달 되더라도 값에 의해 전달되는 서브 개체와 동일하지 않으므로 함수의 컨텍스트가 변경되어 사라집니다. 도와주세요. 감사
편집 난 아직이 문제를 해결하거나 그것을 이해할 수 없다 : 이 하위 폼의 생성자입니다 :
public function __construct($site = null, $options = null) {
if ($site instanceof Diff_Model_Sites) {
$this->_shortName = $site->get('shortName');
$this->_url = $site->get('url');
$this->_content = $site->get('content');
$this->_idSite = $site->get('idSite');
$this->_siteRecord = $site;
$this->_lastChanged = $site->get('lastChanged');
}parent::__construct($options);}
이 내가 값을 설정하는 데 사용 SubformX의 기능이된다.
public function setContent($contentText) {
$this->_siteRecord->content = $contentText;
$this->_content = $contentText;
}
는이 내가하지 두 번째로 업데이트 된 값을 검색 할 수 있어요 주석 라인 값을
public function getContent() {
if (isset($this->_siteRecord)) {
//return $this->_content;
return $this->_siteRecord->content;
}
}
를 얻기 위해 전화를 하위 폼의 기능이다. 이것은 정확하게 동일한 지점에서 정확하게 동일한 방식으로 설정하고 차이를 이해할 수 없기 때문에 나에게 정말 신비입니다.
http://php.net/manual/en/language.oop5.references.php - 그 정보가 문제를 더욱 흐리게 할 수 있음을 인정하지만. 짧게는 * 모든 * 객체는 실제로 객체를 전달하지 않고 컨텍스트에 관계없이 항상 참조로 전달되지만 포인터는 객체를 전달합니다. 즉, 포인터 복사본을 만들더라도 여전히 동일한 것을 가리 킵니다. PHP5에서 객체의 복사본을 만드는 유일한 방법은'clone'입니다. 코드의 나중에 수정되지 않은 것으로 보이는 개체는 수정하지 않았기 때문입니다. – DaveRandom
귀하의 의견을 보내 주셔서 감사합니다. 모든 indexAction은 각 하위 폼의 생성자를 다시 호출하며, 하위 폼을 다시로드하면 저장되기 전에 db에서 요소를 검색합니다. 나는 아직도 어떻게이 행동을 바꾸는 지 알아 내야 만한다. 어떤 도움을 주셔서 감사합니다. 어디 shoud 내가 데이터베이스에서 그들의 가치를로드, 개체를 인스턴스? 감사 – user1439509