Note that there are some explanatory texts on larger screens.

plurals
  1. POusing Zend_Db zf2 module outside of zf2 mvc
    primarykey
    data
    text
    <p>I'm writing a PHP application that is not based on zf2 mvc.</p> <p>I do want to use only the Zend_Db zf2 module. how can I configure my application to know how to find the Zend_Db releveant PHP file where required ?</p> <p>I have zf2 Zend_db module download with phyrus and installed at the location <code>vendor/zf2/php</code>.</p> <p>I tried adding the module to the include path with the following command:</p> <pre><code>set_include_path("../vendor/zf2/php".PATH_SEPARATOR.get_include_path()); </code></pre> <p>I created Model class files relevant to each table (using zend-db-model-generator) inside directory <code>Model/</code>.</p> <p>my main app contains the following:</p> <pre><code>use DrinkManagement\Model\DrinkTable; use Zend\Db\Adapter\Adapter; set_include_path("../vendor/zf2/php".PATH_SEPARATOR.get_include_path()); require_once('Model/DrinkTable.php'); /** @var DrinkManagement\Model\Drink */ $drinkTable=null; $drinkTable = new DrinkTable(); $res=$drinkTable-&gt;getDrink(1); echo var_export($res,1); </code></pre> <p>my DrinkTable class:</p> <pre><code>namespace DrinkManagement\Model; use Zend\Db\TableGateway\AbstractTableGateway, class DrinkTable extends AbstractTableGateway { protected $table ='drink'; protected $tableName ='drink'; public function __construct(Adapter $adapter) { $this-&gt;adapter = $adapter; $this-&gt;resultSetPrototype = new ResultSet(new Drink); $this-&gt;initialize(); } public function fetchAll() { $resultSet = $this-&gt;select(); return $resultSet; } public function newSelect() { return new Select; } public function getSelect(&amp;$select,$columnsArray=array()) { $select = new Select; return $select-&gt;from('drink')-&gt;columns($columnsArray); } public function createIfNotExist($checkColumnsArray,$optionalColumns=array(),&amp;$isRowCreated=null) { $rowset=$this-&gt;select($checkColumnsArray); $row = $rowset-&gt;current(); $id=null; if ($row == null) { $allColumns=array_merge($checkColumnsArray,$optionalColumns); $affectedRows = $this-&gt;insert($allColumns); if ($affectedRows != 1) { throw new \Exception("error: could not add line to db"); } $id=$this-&gt;lastInsertValue; $isRowCreated=true; } else { $id=$row-&gt;drink_id; $isRowCreated=false; } return $id; } //http://stackoverflow.com/questions/6156942/how-do-i-insert-an-empty-row-but-have-the-autonumber-update-correctly public function createEmptyRow() { $row=array( 'drink_id' =&gt; null ); $affectedRows=$this-&gt;insert($row); if ($affectedRows != 1) { throw new \Exception("error: could not add empty row to db"); } $id=$this-&gt;lastInsertValue; return $id; } public function getDrink($id) { $id = (int) $id; $rowset = $this-&gt;select(array('drink_id' =&gt; $id)); $row = $rowset-&gt;current(); if (!$row) { throw new \Exception("Could not find row $id"); } return $row; } public function saveDrink(Drink $drink) { $data = array( 'drink_type_id' =&gt; $drink-&gt;drink_type_id, 'drink_brand_id' =&gt; $drink-&gt;drink_brand_id, 'creation_timestamp' =&gt; $drink-&gt;creation_timestamp, ); $id = (int)$drink-&gt;id; if ($id == 0) { $this-&gt;insert($data); } else { if ($this-&gt;getDrink($id)) { $this-&gt;update($data, array('drink_id' =&gt; $id)); } else { throw new \Exception('Form id does not exit'); } } } public function addDrink($drink_type_id, $drink_brand_id = null, $creation_timestamp = null) { $data = array( 'drink_type_id' =&gt; $drink_type_id, 'drink_brand_id' =&gt; $drink_brand_id, 'creation_timestamp' =&gt; $creation_timestamp, ); $affectedRows=$this-&gt;insert($data); if ($affectedRows != 1) { return null; } return $this-&gt;lastInsertValue; } public function updateDrink($drink_id, $drink_type_id, $drink_brand_id, $creation_timestamp) { $data = array( 'drink_type_id' =&gt; $drink-&gt;drink_type_id, 'drink_brand_id' =&gt; $drink-&gt;drink_brand_id, 'creation_timestamp' =&gt; $drink-&gt;creation_timestamp, ); $this-&gt;update($data, array(drink_id =&gt; $id)); } public function deleteDrink($id) { $this-&gt;delete(array('drink_id' =&gt; $id)); } } </code></pre> <p>when I try to execute my main php application i get the following error message:</p> <pre><code>PHP Fatal error: Class 'Zend\Db\TableGateway\AbstractTableGateway' not found in /Users/ufk/Documents/workspace/tux-drink/TuxDb/mysql/Model/DrinkTable.php on line 10 </code></pre> <p>any ideas how to resolve the issue without adding require_once everywhere ?</p> <p>maybe is there another zf2 component I can use that will autoload the relevant classes?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload