Podsクラス
podsクラス
Padsクラスをインクルードし、初期化する。
コンストラクタ呼出
function pods ( $type = null, $id = null, $strict = false )
パラメ-タ | 内容 |
---|---|
$type | (文字列)pod登録名 |
$id | 数値、オブジェクト(オプション)IDまたはスラッグ。 既存の単一レコードを読み込むためのパラメタ。 単一レコードに対するクエリパラメタの配列も可能。 |
$strict | ブール(オプション)trueを指定すると、レコードの存在是非をtrue/falseで返す。 通常の戻り値はPodsオブジェクト Podsアイテムそのものの存在是非は、静的メソッド pods::exists() を使用 |
戻り値
ブール値またはPodsオブジェクト(パラメータによる)
プログラム例1
<?php // Podsオブジェクトを生成して取得 $mypod = pods( 'mypod' ); // 特定レコードを指定してオブジェクト取得 $mypod = pods( 'mypod', $id_or_slug ); // クエリパラメタを作成して取得 $params = array( 'orderby' => 't.name DESC', 'limit' => 15, 'where' => 't.name != "Buster"' ); $mypod = pods( 'mypod', $params ); // こういう記法でもOK $mypod = pods( 'mypod' )->find( $params ); // こうやっても同じ $mypod = pods( 'mypod' ); $mypod->find( $params ); // 取得値をループして表示 while ( $mypod->fetch() ) { echo '<p>' . $mypod->display( 'my_field_name' ) . '</p>'; } // レコードの有無をチェック // at http://mysite.com/bunnies/voodoo-rabbit/ $slug = pods_var( 1, 'url' ); // get the second level of the current URL $pods = pods( 'bunny', $slug ); if ( $pods->exists() ) { // This bunny exists! } else { // This bunny was not found, better send a 404. // This only works if it's ran in a Pod Page Precode // or if you set the $pods global to this before the // theme runs, which is usually right after the // 'after_setup_theme' action. $pods = 404; }
Add Default Values To Fields Output a Pods Form for Pod 'fruit' with two fields, 'yellow_fruit' and 'blue_fruit' with the field 'yellow_fruit' pre-populated with the value 'Banana'.
<?php //Create pods object $pods = pods( 'fruits' ); //setup fields array $params = array( 'yellow_fruit' => array( 'default' => 'Banana' ), 'orange_fruit' ); echo $pods->form( $params ); ?> Use strict mode and pods::exists() to avoid errors if Pod or Pod item do not exist Illustrates the difference between strict mode, which returns false if the pod does not exist, versus pods::exists()