Geliştireceğim yeni projemde Zendframework kullanmaya karar verdiğim den bu yana ZendFramework üzerinde çalışıyorum. Oldukça kapsamlı bir framwork hazırlamış Zend ekibi. Diğer bir çok framework ü inceledikten sonra ZendFramework de karar kıldım. Bir çok modüle sahip ve modüller birbirinelerine ihtiyaö duymadan tekil olarak da projelerinizde kullanılabilir. İhtiyaç duyduğunuz birden fazla modülü de kullanabilisiniz. Mesela sadece Zend_Conttrller ve Zend_DB yi kullarak projenizi geliştirmeniz mümkün. Çalışmam sırasında karalama defteri olarak kullandığım dökümanı sizinle paylaşıyorum. Olduça uzun bir döküman , ihtiyaç duyan arkadaşlara şimdiden hayırlı olsun.


Bu döküman Türkçe veİngilizce olarak karma bir vaziyette ve üzerinde çok da özen gösterdim diyemem. Çalışma anımda alıp bir kenara kaydettiklerimin derlemesi olarak görebilirsiniz.

  1.  
  2. Zend Temel MVC Yapısının Çalıştırılması
  3. ——————————————————————————-
  4.  
  5. Uygulama Hiyerarşisi
  6. ===============================================================================
  7. application/
  8.     config/
  9.     controllers/
  10.         IndexController.php
  11.         ErrorController.php
  12.     layouts/
  13.         scripts/
  14.     models/
  15.     views/
  16.         scripts/
  17.             index/
  18.                 index.phtml
  19.             error/
  20.                 error.phtml
  21.         helpers/
  22.         filters/
  23. html/
  24.     .htaccess
  25.     index.php
  26.  
  27. Dosya İçerikleri
  28. ===============================================================================
  29.  
  30. .htaccess
  31. ===============================================================================
  32. RewriteEngine On
  33. RewriteCond %{REQUEST_FILENAME} -s [OR]
  34. RewriteCond %{REQUEST_FILENAME} -l [OR]
  35. RewriteCond %{REQUEST_FILENAME} -d
  36. RewriteRule ^.*$ - [NC,L]
  37. RewriteRule ^.*$ /zend/proje_iskeleti/public/index.php [NC,L]
  38. index.php
  39. ===============================================================================
  40. define(‘APPLICATION_PATH’, realpath( dirname(__FILE__). ‘/../application/’));
  41.  
  42.     realpath(APPLICATION_PATH . ‘/../library’)
  43.     . PATH_SEPARATOR . get_include_path()
  44. );
  45.  
  46. require_once "Zend/Loader.php";
  47. Zend_Loader::registerAutoload();
  48.  
  49. Zend_Controller_Front::run(APPLICATION_PATH . ‘/controllers’);
  50.  
  51. IndexController.php
  52. ===============================================================================
  53.  
  54. class IndexController extends Zend_Controller_Action
  55. {
  56.     public function indexAction()
  57.     {
  58.     }
  59. }
  60.  
  61. ErrorController.php
  62. ===============================================================================
  63.  
  64. class ErrorController extends Zend_Controller_Action
  65. {
  66.     public function errorAction()
  67.     {
  68.     }
  69. }
  70.  
  71. index.phtml
  72. ===============================================================================
  73.  
  74.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  75. <h1>Merhaba, Dünya :)</h1>
  76. error.phtml
  77. ===============================================================================
  78.  
  79.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  80. <h1>Bir hata oluştu!</h1>
  81. Zend_Controller_Front  ile kullanılabilecekler
  82. ===============================================================================
  83.  
  84. //obje oluşturmak için:
  85. $front = Zend_Controller_Front::getInstance();
  86.  
  87. // Set the default controller directory:
  88. $front->setControllerDirectory(‘../application/controllers’);
  89.  
  90. // Set several module directories at once:
  91. $front->setControllerDirectory(array(
  92.     ‘default’ => ‘../application/controllers’,
  93.     ‘blog’    => ‘../modules/blog/controllers’,
  94.     ‘news’    => ‘../modules/news/controllers’,
  95. ));
  96.  
  97. // Add a ‘foo’ module directory:
  98. $front->addControllerDirectory(‘../modules/foo/controllers’, ‘foo’);
  99.  
  100. //MVC mevzusunu başlatır.
  101. $front->dispatch();
  102.  
  103. Şu durumda genel sıralama şöyledir:
  104. $front = Zend_Controller_Front::getInstance();
  105. $front->setControllerDirectory(‘../application/controllers’);
  106. $front->dispatch();
  107.  
  108. Bunların üçünü tek başına yapan fonksiyon ise:
  109. Zend_Controller_Front::run(‘../application/controllers’);
  110.  
  111. //dispatch işleminden önce çağrılır. parametr true ise ekrana çıktı olmaz
  112. //değişkene set edilebilir.
  113. $front->returnResponse(true);
  114.  
  115. two-step view
  116. ===============================================================================
  117. 2 adımda ekran çıktısı oluşturulur. birincisi controller vasıtasıyla esas
  118. detayı içeren göbek kısmı render ediilir. ikinci adımda dış layout a bu kod
  119. bindirilir.
  120. db-functions :: Zend_Db_Adapter_Abstract  nesnesinden türeyen objedir
  121. ===============================================================================
  122. bootsrap.php de şu şekilde tnaımlaması yapılır
  123.  
  124. $db = Zend_Db::factory($conf->db->adapter, $dbConfig);
  125. Zend_Db_Table::setDefaultAdapter($db);
  126. Zend_Registry::set(‘db’, $db);
  127. unset($db);
  128.  
  129. daha sonra herhangi bir "model" içerisindeyken şu şekilde kullanılır
  130. $db = Zend_Registry::get(‘db’);
  131.  
  132. factory vasıtasıyla obje oluşturulur ama DB ye connection kurulmaz. dolasıyıla bu
  133. kodların yazımının bir DB masrafı yoktur.
  134.  
  135. $db->getConnection() :: DB ile bağlantı açar.
  136. $db->getConfig() :: DB ye bağlanmakta kullanılan ayar değişkenlerini verir
  137. $db->setProfiler(obje veya true) :: sql çalışma zamanlarını öğrenmek için profilingi aktif eder
  138. $db->getProfiler() :: sorgu sonucundaki profiling değerini verir. dizi şeklinde tüm sorgular için
  139.         değeri tutar
  140. $db->query($sql, $bind = array()) :: sorguyu direk çalıştırır. sorguda ? geçiyorsa her ? için
  141.         sırayla  değerleri $bind parametresinde set edilir.
  142. $db->beginTransaction() :: transaction başlatır
  143. $db->commit() :: transaction ı commit eder
  144. $db->rollBack() :: transaction ı geri alır
  145.  
  146. $db->insert($table, array $bind) :: tablo adı ve değerler parametre oalrak geçilir. DB ye
  147.         insert atar.
  148.  
  149.         $data = array("adi"=>‘orhan’, ’soyadi’=‘doğan’, ‘yasi’=>‘30′);
  150.         $table =‘employer’;
  151.         $db->insert($table, $data);
  152.  
  153. $db->update($table, array $bind, $where = ) ::insert  den tek farkı update için where
  154.         sartını istemesdir.
  155.  
  156.         ÖRNEK 1:
  157.         $data = array("adi"=>‘orhan’, ’soyadi’=‘doğan’, ‘yasi’=>‘30′);
  158.         $table =‘employer’;
  159.         $where =‘id=3′;
  160.         $db->insert($table, $data, $where);
  161.  
  162.         ÖRNEK 2:
  163.         $data = array(
  164.             ‘updated_on’      => ‘2007-03-23′,
  165.             ‘bug_status’      => ‘FIXED’
  166.         );
  167.  
  168.         $where[] = "reported_by = ‘goofy’";
  169.         $where[] = "bug_status = ‘OPEN’";
  170.  
  171.         $n = $db->update(‘table_bugs’, $data, $where);
  172.  
  173. $db->delete($table, $where = ) :: tablodan kayıt siler.
  174.  
  175.         $table =‘employer’;
  176.         $where =‘id=3′;
  177.         $db->insert($table, $where);
  178.  
  179. $db->select() :: Creates and returns a new Zend_Db_Select object for this adapter.
  180.  
  181. $db->getFetchMode() :: fetch modu verir.
  182.  
  183. $db->fetchAll($sql, $bind = array(), $fetchMode = null) :: $sql ile belirtilen ifade
  184.         çalıştırılır. ifade de ? varsa sırasıyla her soru işareti için $bind dizisinde
  185.         bir değer olmalıdır. $fetchMode istenirse verilebilir
  186.  
  187. $db->fetchRow($sql, $bind = array(), $fetchMode = null) :: sorgu sonucundaki ilk
  188.         satırı çeker
  189.  
  190. $db->fetchAssoc($sql, $bind = array()) ::  Fetches all SQL result rows as an
  191.         associative array.
  192.  
  193. $db->fetchCol($sql, $bind = array()) :: Fetches the first column of all SQL
  194.         result rows as an array.
  195.  
  196. $db->fetchPairs($sql, $bind = array()) :: Fetches all SQL result rows as
  197.         an array of key-value pairs.
  198.  
  199. $db->fetchOne($sql, $bind = array()) :: Fetches the first column of the
  200.         first row of the SQL result.
  201.  
  202. $db->quote($value, $type = null) :: Safely quotes a value for an SQL statement.
  203.         If an array is passed as the value, the array values are quoted
  204.         and then returned as a comma-separated string.
  205.  
  206. $db-> quoteInto($text, $value, $type = null, $count = null) :: Quotes a value and
  207.         places into a piece of text at a placeholder. The placeholder is a
  208.         question-mark; all placeholders will be replaced with the quoted value.
  209.  
  210.      $text = "WHERE date < ?";
  211.      $date = "2005-01-02";
  212.      $safe = $sql->quoteInto($text, $date);
  213.      // $safe = "WHERE date < ‘2005-01-02′"
  214.  
  215. $db->quoteIdentifier($ident, $auto=false) ::  Quotes an identifier
  216.  
  217.         $adapter->quoteIdentifier(‘myschema.mytable’); //Returns: "myschema"."mytable"
  218.         veya
  219.         $adapter->quoteIdentifier(array(‘myschema’,‘my.table’)); //Returns: "myschema"."my.table"
  220.  
  221. $db->listTables() ::  Returns a list of the tables in the database.
  222.  
  223. $db->describeTable($tableName, $schemaName = null) ::  Returns the column descriptions for a table.     ,
  224.  
  225. $db->isConnected() ::  Test if a connection is active
  226. $db->closeConnection(); bağlantıyı kapatır
  227. $db->lastInsertId($tableName = null, $primaryKey = null); Gets the last ID generated automatically
  228.         by an IDENTITY/AUTOINCREMENT column.
  229. $db->setFetchMode($mode) :: Set the fetch mode.
  230. $db->limit($sql, $count, $offset = 0) :: Adds an adapter-specific LIMIT clause to the SELECT statement
  231. $db->getServerVersion() :: Retrieve server version in PHP style
  232.  
  233. "SELECT MAX(id)+1 FROM table" yapısı KUL-LA-NIL-MA-MA-LIDIR
  234. ===============================================================================
  235. çoklu-istemci ortamında o anda hangi "yeni-satır" işleminin yürütüldüğü %100
  236. kestirilemeyeceği için bu ifade ile id üretmek çok hatalarak sebep olur.
  237. Bunun yerine ara bir tabloya insert atılmalı ve $db->lastInsertId() ile bu id
  238. alınıp kullanılmalıdır.
  239.  
  240. Zend_Db_Profiler  :: SQL lerin çalışma süre istatistikleri
  241. ===============================================================================
  242. $params = array(
  243.     ‘host’     => ‘127.0.0.1′,
  244.     ‘username’ => ‘webuser’,
  245.     ‘password’ => ‘xxxxxxxx’,
  246.     ‘dbname’   => ‘test’
  247.     ‘profiler’ => true  // true: profiler aktif   false:profiler pasif
  248. );
  249. $db = Zend_Db::factory(‘PDO_MYSQL’, $params);
  250.  
  251. $db->getProfiler()->setEnabled(false); //profiler ı aktif et
  252. $db->getProfiler()->setEnabled(true); //profiler ı pasif et
  253.  
  254. $profiler = $db->getProfiler();
  255. $profiler->getTotalNumQueries() :: returns the total number of queries that have been profiled.
  256. $profiler->getTotalElapsedSecs() :: returns the total number of seconds elapsed for all profiled queries.
  257. $profiler->getQueryProfiles() :: returns an array of all query profiles
  258. $profiler->getLastQueryProfile() :: returns the last (most recent) query profile, regardless of
  259.         whether or not the query has finished (if it hasn‘t, the end time will be null)
  260. $profiler->clear() :: clears any past query profiles from the stack.
  261.  
  262. en uzun çalışan sorgunun gösterilmesi için bu yapı kullanılabili
  263. $totalTime    = $profiler->getTotalElapsedSecs();
  264. $queryCount   = $profiler->getTotalNumQueries();
  265. $longestTime  = 0;
  266. $longestQuery = null;
  267. foreach ($profiler->getQueryProfiles() as $query) {
  268.    if ($query->getElapsedSecs() > $longestTime) {
  269.        $longestTime  = $query->getElapsedSecs();
  270.        $longestQuery = $query->getQuery();
  271.    }
  272. }
  273.  
  274. // Only profile queries that take at least 5 seconds:
  275. $profiler->setFilterElapsedSecs(5);
  276. // Profile all queries regardless of length:
  277. $profiler->setFilterElapsedSecs(null);
  278.  
  279. Sorguların tipine göre filtreleme:::
  280. // profile only SELECT queries
  281. $profiler->setFilterQueryType(Zend_Db_Profiler::SELECT);
  282.  
  283. // profile SELECT, INSERT, and UPDATE queries
  284. $profiler->setFilterQueryType(Zend_Db_Profiler::SELECT |
  285.                              Zend_Db_Profiler::INSERT |
  286.                              Zend_Db_Profiler::UPDATE);
  287.  
  288. // profile DELETE queries
  289. $profiler->setFilterQueryType(Zend_Db_Profiler::DELETE);
  290.  
  291. // Remove all filters
  292. $profiler->setFilterQueryType(null);
  293.  
  294. Zend_Db_Profiler::CONNECT: connection operations, or selecting a database.
  295. Zend_Db_Profiler::QUERY: general database queries that do not match other types.
  296. Zend_Db_Profiler::INSERT: any query that adds new data to the database, generally SQL INSERT.
  297. Zend_Db_Profiler::UPDATE: any query that updates existing data, usually SQL UPDATE.
  298. Zend_Db_Profiler::DELETE: any query that deletes existing data, usually SQL DELETE.
  299. Zend_Db_Profiler::SELECT: any query that retrieves existing data, usually SQL SELECT.
  300. Zend_Db_Profiler::TRANSACTION: any transactional operation, such as start transaction, commit, or rollback.
  301.  
  302. Zend_Db_Table  KULLANIMI
  303. ===============================================================================
  304. aşağıdaki şekilde conenction objesi table nesnesine set edilebilir
  305. $db = Zend_Db::factory(’PDO_MYSQL‘, $options);
  306. $table = new Bugs(array(’db‘ => $db));
  307.  
  308. veya
  309.  
  310. $db = Zend_Db::factory(’PDO_MYSQL‘, $options);
  311. Zend_Db_Table_Abstract::setDefaultAdapter($db);
  312.  
  313. şeklinde tanımlama yapıldıktan sonra kodun geri kalan kısmında
  314.  
  315. $table = new Bugs();
  316.  
  317. şeklinde tanımlama yapılabilir. Registery  ye yapılmış db de kullanılabilirdi.
  318.  
  319. // First alternative:
  320. class Member extends Zend_Db_Table_Abstract
  321. {
  322.    protected $_schema = ‘bz‘;
  323.    protected $_name   = ‘member‘;
  324.    protected $_primary = ‘member_id‘;
  325. }
  326.  
  327. VEYA
  328. // Second alternative:
  329. class Member extends Zend_Db_Table_Abstract
  330. {
  331.    protected $_name = ‘bz.member_id‘;
  332.    protected $_primary = ‘member_id‘;
  333. }
  334.  
  335. Table initialization: sınıf construct olurken init () fonksiyonu otomatik çalışır.
  336. sınıf yapılandırılırken çalışması istenen kodlar buraqya yazılır.
  337.  
  338. class Member extends Zend_Db_Table_Abstract
  339. {
  340.    protected $_debug_member_id;
  341.  
  342.    public function init()
  343.    {
  344.        $this->_debug_member_id =1234;
  345.    }
  346. }
  347. _______________________________________________________________________________
  348.  
  349. INSERT İŞLEMİ:::
  350. $table = new Bugs();
  351. $data = array(
  352.    ’created_on‘      => ‘2007-03-22‘,
  353.    ’bug_description‘ => ‘Something wrong‘,
  354.    ’bug_status‘      => ‘NEW
  355. );
  356. $table->insert($data);
  357.  
  358. Example of inserting expressions to a Table :::
  359. $table = new Bugs();
  360. $data = array(
  361.    ’created_on‘      => new Zend_Db_Expr(’CURDATE()‘),
  362.    ’bug_description‘ => ‘Something wrong‘,
  363.    ’bug_status‘      => ‘NEW
  364. );
  365.  
  366. burada  new Zend_Db_Expr(’CURDATE()‘) kullanılmıştır. mysql ifaqdelerini set etmek için
  367. Zend_Db_Expr  sınıfı kullanılır
  368.  
  369. _______________________________________________________________________________
  370.  
  371. UPDATE İŞLEMİ:::
  372. $table = new Bugs();
  373. $data = array(
  374.    ’updated_on‘      => ‘2007-03-23‘,
  375.    ’bug_status‘      => ‘FIXED
  376. );
  377. $where = $table->getAdapter()->quoteInto(’bug_id = ?‘, 1234);
  378. $table->update($data, $where);
  379.  
  380. _______________________________________________________________________________
  381.  
  382. DELETE İŞLEMİ:::
  383. $table = new Bugs();
  384. $where = $table->getAdapter()->quoteInto(’bug_id = ?‘, 1235);
  385. $table->delete($where);
  386.  
  387. _______________________________________________________________________________
  388.  
  389. PRIMARY KEY İLE SATIR BULMA:::
  390. $table = new Bugs();
  391.  
  392. // Find a single row
  393. // Returns a Rowset
  394. $rows = $table->find(1234);
  395.  
  396. // Find multiple rows
  397. // Also returns a Rowset
  398. $rows = $table->find(array(1234, 5678));
  399.  
  400. burada dönen değer Zend_Db_Table_Rowset_Abstract   sınıfındandır
  401.  
  402. _______________________________________________________________________________
  403.  
  404. SORGULAMA YAPMA:::
  405. // Fetching a rowset
  406. $rows = $table->fetchAll(’bug_status = "NEW"‘, ‘bug_id ASC‘, 10, 0);
  407. $rows = $table->fetchAll($table->select()->where(’bug_status = ?‘, ‘NEW‘)
  408.                                         ->order(’bug_id ASC‘)
  409.                                         ->limit(10, 0));
  410.  
  411. // Fetching a single row
  412. $row = $table->fetchRow(’bug_status = "NEW"‘, ‘bug_id ASC‘);
  413. $row = $table->fetchRow($table->select()->where(’bug_status = ?‘, ‘NEW‘)
  414.                                        ->order(’bug_id ASC‘));
  415.  
  416. YA DA
  417.  
  418. $table = new Bugs();
  419. $order  = ‘bug_id desc ‘;
  420.  
  421. // Return the 21st through 30th rows
  422. $count  = 10;
  423. $offset = 20;
  424. $select = $table->select()->where(array(’bug_status = ?‘ => ‘NEW‘))
  425.                          ->order($order)
  426.                          ->limit($count, $offset);
  427. $rows = $table->fetchAll($select);
  428.  
  429. _______________________________________________________________________________
  430.  
  431. İSTENİLEN SÜTUNLARIN ÇAĞRILMASI :::
  432. $table = new Bugs();
  433. $select = $table->select();
  434. $select->from($table, array(’bug_id‘, ‘bug_description‘))
  435.       ->where(’bug_status = ?‘, ‘NEW‘);
  436. $rows = $table->fetchAll($select);
  437.  
  438. _______________________________________________________________________________
  439.  
  440. İFADENİN SÜTUN OLARAK GETİRİLMESİ::
  441. $table = new Bugs();
  442. $select = $table->select();
  443. $select->from($table,
  444.              array(’COUNT(reported_by) as `count`‘, ‘reported_by‘))
  445.       ->where(’bug_status = ?‘, ‘NEW‘)
  446.       ->group(’reported_by‘);
  447.  
  448. $rows = $table->fetchAll($select);
  449.  
  450. _______________________________________________________________________________
  451.  
  452. JOIN İLE SORGULAMA :::
  453. $table = new Bugs();
  454.  
  455. // retrieve with from part set, important when joining
  456. $select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
  457. $select->setIntegrityCheck(false)
  458.       ->where(’bug_status = ?‘, ‘NEW‘)
  459.       ->join(’accounts‘, ‘accounts.account_name = bugs.reported_by‘)
  460.       ->where(’accounts.account_name = ?‘, ‘Bob‘);
  461.  
  462. $rows = $table->fetchAll($select);
  463.  
  464. _______________________________________________________________________________
  465.  
  466. TABLO HAKKINDA META DATA ALMA
  467. $table = new Bugs();
  468. $select  = $table->select()->where(’bug_status = ?‘, ‘NEW‘)
  469.                           ->order(’bug_id‘);
  470. $row = $table->fetchRow($select);
  471.  
  472. _______________________________________________________________________________
  473.  
  474. USING A METADATA CACHE FOR A SPECIFIC TABLE OBJECT :::
  475. // First, set up the Cache
  476. $frontendOptions = array(
  477.    ’automatic_serialization‘ => true
  478.    );
  479.  
  480. $backendOptions  = array(
  481.    ’cache_dir‘                => ‘cacheDir
  482.    );
  483.  
  484. $cache = Zend_Cache::factory(’Core‘,
  485.                             ‘File‘,
  486.                             $frontendOptions,
  487.                             $backendOptions);
  488.  
  489. // A table class is also needed
  490. class Bugs extends Zend_Db_Table_Abstract
  491. {
  492.    // …
  493. }
  494.  
  495. // Configure an instance upon instantiation
  496. $bugs = new Bugs(array(’metadataCache‘ => $cache));
  497.  
  498. _______________________________________________________________________________
  499.  
  500. DEFINING CUSTOM LOGIC FOR INSERT, UPDATE, AND DELETE :::
  501.  
  502. bu yapıyı kullanarak araqya loglama veya başka tablolara kayıt atma imkanımız olur.
  503. veya örnek koddaki gibi bazı field ları set edebiliriz.
  504.  
  505. class Bugs extends Zend_Db_Table_Abstract
  506. {
  507.    protected $_name = ‘bugs‘;
  508.  
  509.    public function insert(array $data)
  510.    {
  511.        // add a timestamp
  512.        if (empty($data[’created_on‘])) {
  513.            $data[’created_on‘] = time();
  514.        }
  515.        return parent::insert($data);
  516.    }
  517.  
  518.    public function update(array $data, $where)
  519.    {
  520.        // add a timestamp
  521.        if (empty($data[’updated_on‘])) {
  522.            $data[’updated_on‘] = time();
  523.        }
  524.        return parent::update($data, $where);
  525.    }
  526. }
  527.  
  528. _______________________________________________________________________________
  529.  
  530. CUSTOM METHOD TO FIND BUGS BY STATUS :::
  531. aramalar için özel fonksyionlar yazabiliriz. böylece herhangi bir sql yazmadan
  532. aradığımız değerleri parametre olarak geçerek erişebiliriz.
  533.  
  534. class Bugs extends Zend_Db_Table_Abstract
  535. {
  536.    protected $_name = ‘bugs‘;
  537.  
  538.    public function findByStatus($status)
  539.    {
  540.        $where = $this->getAdapter()->quoteInto(’bug_status = ?‘, $status);
  541.        return $this->fetchAll($where, ‘bug_id‘);
  542.    }
  543. }
  544.  
  545. Zend_Db_Table_Row  KULLANIMI
  546. ===============================================================================
  547. Zend_Db_Table_Row sınıfını içerisinde birçok Zend_Db_Table_Rowset  olan ve
  548. onlar üzernde işlem yapan bir üst sınıf olarak düşünebiliriz.
  549. Zend_Db_Table_Row  nesnesinin döndürdüğü değerler  Zend_Db_Table_Row  sınıfındandır.
  550.  
  551. Zend_Db_Table_Abstract soyut sınıfının find() ve fetchAll() fonksiyonları
  552. Zend_Db_Table_Rowset sınıfı tipinde değer döndürür. fetchRow() fonksiyonu ise
  553. Zend_Db_Table_Row sınıfı türünde değer döner.
  554.  
  555. EXAMPLE OF FETCHING A ROW ::: Zend_Db_Table_Row
  556. $bugs = new Bugs();
  557. $row = $bugs->fetchRow($bugs->select()->where(’bug_id = ?‘, 1));
  558.  
  559. _______________________________________________________________________________
  560.  
  561. EXAMPLE OF READING A ROW IN A ROWSET ::: Zend_Db_Table_Row
  562.  
  563. $bugs = new Bugs();
  564. $rowset = $bugs->fetchAll($bugs->select()->where(’bug_status = ?‘, 1));
  565. $row = $rowset->current();
  566. echo $row->bug_description; //bug_description sütununun değeri ekrana basılıyor
  567.  
  568. _______________________________________________________________________________
  569.  
  570. RETRIEVING ROW DATA AS AN ARRAY ::: Zend_Db_Table_Row
  571.  
  572. $bugs = new Bugs();
  573. $row = $bugs->fetchRow($bugs->select()->where(’bug_id = ?‘, 1));
  574.  
  575. // Get the column/value associative array from the Row object
  576. $rowArray = $row->toArray();
  577.  
  578. // Now use it as a normal array
  579. foreach ($rowArray as $column => $value) {
  580.    echo "Column: $column\n";
  581.    echo "Value:  $value\n";
  582. }
  583.  
  584. _______________________________________________________________________________
  585.  
  586. WRITING ROWS TO THE DATABASE ::: Zend_Db_Table_Row
  587.  
  588. $bugs = new Bugs();
  589. $row = $bugs->fetchRow($bugs->select()->where(’bug_id = ?‘, 1));
  590.  
  591. // Change the value of one or more columns
  592. $row->bug_status = ‘FIXED‘;
  593.  
  594. // UPDATE the row in the database with new values
  595. $row->save();
  596.  
  597. _______________________________________________________________________________
  598.  
  599. INSERTING A NEW ROW ::: Zend_Db_Table_Row
  600.  
  601. $bugs = new Bugs();
  602. $newRow = $bugs->createRow();
  603.  
  604. // Set column values as appropriate for your application
  605. $newRow->bug_description = ‘…description…‘;
  606. $newRow->bug_status = ‘NEW‘;
  607.  
  608. // INSERT the new row to the database
  609. $newRow->save();
  610.  
  611. _______________________________________________________________________________
  612.  
  613. POPULATING A NEW ROW FOR A TABLE ::: Zend_Db_Table_Row
  614.  
  615. $data = array(
  616.    ’bug_description‘ => ‘…description…‘,
  617.    ’bug_status‘      => ‘NEW
  618. );
  619.  
  620. $bugs = new Bugs();
  621. $newRow = $bugs->createRow($data);
  622.  
  623. // INSERT the new row to the database
  624. $newRow->save();
  625.  
  626. yukarıdakine alternatif olarak setFromArray() kullanarak da yeni satır eklenebilir
  627.  
  628. $bugs = new Bugs();
  629. $newRow = $bugs->createRow();
  630.  
  631. // Data are arranged in an associative array
  632. $data = array(
  633.    ’bug_description‘ => ‘…description…‘,
  634.    ’bug_status‘      => ‘NEW
  635. );
  636.  
  637. // Set all the column values at once
  638. $newRow->setFromArray($data);
  639.  
  640. // INSERT the new row to the database
  641. $newRow->save();
  642.  
  643. _______________________________________________________________________________
  644.  
  645. Deleting a row ::: Zend_Db_Table_Row
  646.  
  647. $bugs = new Bugs();
  648. $row = $bugs->fetchRow(’bug_id = 1‘);
  649.  
  650. // DELETE this row
  651. $row->delete();
  652.  
  653. _______________________________________________________________________________
  654.  
  655. SERIALIZING A ROW ::: Zend_Db_Table_Row
  656.  
  657. $bugs = new Bugs();
  658. $row = $bugs->fetchRow(’bug_id = 1‘);
  659.  
  660. // Convert object to serialized form
  661. $serializedRow = serialize($row);
  662.  
  663. // Now you can write $serializedRow to a file, etc.