Skip to content

Instantly share code, notes, and snippets.

@ertankayalar
Created June 22, 2013 14:05
Show Gist options
  • Save ertankayalar/5840983 to your computer and use it in GitHub Desktop.
Save ertankayalar/5840983 to your computer and use it in GitHub Desktop.
doctrine notları
<?php
/*
doctrine ile kodlama yaparken mümkün oldukça array olarak döndürelim
---------------------------------------------------------------------
*/
public function getUserId($username) {
$user = Doctrine_Query::create()
->select('u.id, u.user_name')
->from('User u')
->where('u.user_name = ?', $user_name)
->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
if ($user['id'])
return $user['id'];
else
return 0;
}
/*
isim verirken Doctrine_Record Doctrine_Table gibi objeclere ismin sonuna Table ekleyelim
-------------------------------------------------------------------------------------------
*/
public function saveShipAddress($addr) {
$addressTable = Address::factory();
$addr['site_id'] = SITE_ID;
if ($this->ship_address_id == 0) {
$addressTable->fromArray($addr);
$addressTable->save();
$this->ship_address_id = $addressTable->id;
}
else
{
$addr['id'] = $this->ship_address_id;
$upAdr = $addressTable->findById($this->ship_address_id);
$upAdr->fromArray($addr);
$upAdr->save();
}
return $this;
}
/*
if else komutlarını azaltalım
------------------------------------
? : sistemini kullanalım
controller içerisindeki kodları düzenlemek için fonksyionlar kullanalım
---------------------------------------------------------------------
action içinde tüm koşulları kontrol ederek yazmak yerine metodlara havale edelim
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment