Last active
August 29, 2015 14:12
-
-
Save kaioken/9538c5e1348e2150dd01 to your computer and use it in GitHub Desktop.
Phalcon Cheat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// para hacer query directo de un modelo utilizando su phql | |
$model::query() | |
->where('field = :bindparam:') | |
->andWhere( "field2 = '1' ") | |
->bind( ['bindparam' => '2'] ) | |
->order('field ASC') | |
->limit(10) | |
->cache(['key' => 'optionalifyouwant' , 'lifetime' => 'optionalalso']) | |
->execute(); | |
//catch errores que devuelve un modulo si fallo guardar | |
$model = new News(); | |
$model->title = 'hola'; | |
$model->content = 'hellos world'; | |
//throw error | |
if (!$model->save()) | |
{ | |
//messages | |
foreach ($model->getMessages() as $message) | |
{ | |
throw new Exception($message); | |
//or flash message in controller | |
$this->flash->error($message); | |
} | |
} | |
// Find record with id = 3 | |
$robot = Robots::findFirst(3); | |
//find one record with condicional | |
$robots = Robots::findFirst([ | |
"columns” => "id, name”, | |
"conditions" => "type = ?1", | |
"bind" => [1 => "virtual"], | |
"order" => "id DESC" , | |
"limit" => "limit" => 10 / "limit" => ["number" => 10, "offset" => 5], | |
"group” => "name, status”, | |
"cache” => array("lifetime” => 3600, "key” => "my-find-key”), | |
]); | |
//find all record with condicional | |
$robots = Robots::find([ | |
"columns” => "id, name”, | |
"conditions" => "type = ?1", | |
"bind" => [1 => "virtual"], | |
"order" => "id DESC" , | |
"limit" => "limit" => 10 / "limit" => ["number" => 10, "offset" => 5], | |
"group” => "name, status”, | |
"cache” => array("lifetime” => 3600, "key” => "my-find-key”), | |
]); | |
//validate if we have records | |
if($robots) if no records found it returns false | |
//count the result set para saber si trajo algo | |
$robots->count(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment