Pluf Framework

Sign in or create your account | Project List | Help

Pluf Framework Commit Details

Date:2009-05-22 13:17:05 (1 year 3 months ago)
Author:Loïc d'Anterroches
Commit:f1f23bc18093471e76cbc50e7e7c854138c3cf24
Message:Added a shortcuts to get one object or throw a 404 exception.

Files: src/Pluf/Shortcuts.php (1 diff)

Change Details

src/Pluf/Shortcuts.php
4444}
4545
4646/**
47 * Get an object by SQL or raise a 404 error.
48 *
49 * Usage:
50 * <pre>
51 * $obj = Pluf_Shortcuts_GetOneOr404('MyApp_Model',
52 * 'path=%s AND status=%s',
53 * array('welcome', 1));
54 * </pre>
55 *
56 * @param string Model
57 * @param string Base SQL request
58 * @param string Parameters for the base SQL
59 * @return Object The found object
60 */
61function Pluf_Shortcuts_GetOneOr404($object, $bsql, $psql)
62{
63    $sql = new Pluf_SQL($bsql, $psql);
64    $item = Pluf::factory($object)->getOne(array('filter' => $sql->gen()));
65    if ($item != null) {
66        return $item;
67    }
68    throw new Pluf_HTTP_Error404();
69}
70
71/**
4772 * Render a template file and an array as a reponse.
4873 *
4974 * If a none null request object is given, the context used will

Archive Download the corresponding diff file

Branches:
develop
master