Zend_Db_Table
select()
Zend_Dbを明示的に使用しない場合でも、ほとんどの場合、引用符が提供されます。
//query is broken into multiple line for more clarity and is just an example
$select = $this->getAdapter()->select();
$select->from('friendships');
$select->where('user1 = ?', $user1);
$select->where('user2 = ?', $user2);//successive where() will tie together with AND
$select->orWhere('user1 = ?', $user2);
クエリがオブジェクトを使用している限り、select()
引用符で囲まれます。
選択オブジェクトが使用できない場合に挿入または更新を行う必要がある場合は、quoteInto()を使用します。
//in your DbTable models
$where = $this->getAdapter()->quoteInto('user1 = ?', $user1);
$result = $this->getAdapter()->update($data, $where);
2番目の質問は、quoteInto関数に複数の値を入れるにはどうすればよいですか?
APIは次のとおりです。
/* @param string $text The text with a placeholder.
* @param mixed $value The value to quote.
* @param string $type OPTIONAL SQL datatype
* @param integer $count OPTIONAL count of placeholders to replace
* @return string An SQL-safe quoted value placed into the original text.
*/
public function quoteInto($text, $value, $type = null, $count = null)
したがって、複数の値は実際にはサポートされていませんがquoteInto()
、他の引用関数を使用できます。
モデルの入力をどのように検証しますか?(フォームではありません)
フォームの検証に使用するのと同じクラスを使用し、Zend_ValidateとZend_Filterを使用します。最も簡単な方法は、Zend_Filter_Input()を使用することです。
//multiple methods demonstrated
$filters = array('*'=>'StringTrim','zip'=> new Zend_Filter_Digits());
$validators = array('name'=>'Alnum');
$input = new Zend_Filter_Input($filters, $validators, $data);
if ($input->isValid()){//do some stuff}
最後の質問ですが、アプリケーションusign zendフレームワークを作成するためにどの手順に従いますか?つまり、最初にプロジェクトを計画し、次にモデルを作成し、次にコントローラーを作成し、最後にビューを作成します(あなたが一人でプロジェクトに取り組んでいると仮定します)。
それはあなたのアプリケーションです、あなたが望むようにそれをしてください。詮索するつもりはありませんが、アプリケーションは必要なものを知らせてくれます。通常、表示するものと操作するデータがあります。次に、計画を立ててください。