--I started with the ORM Redbeans, and by following their tutorial I tested the model. I have correctly set the namespaces, but when I call the R :: store method, the update function of the model does not trigger, dont FUSE.
A part of my controller :
<?php
namespace App\Controllers;
use DDesrosiers\SilexAnnotations\Annotations as SLX;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use RedBeanPHP\R;
/**
* @SLX\Controller(prefix="article")
*/
class ArticleController
{
/**
* @SLX\Route(
* @SLX\Request(method="GET", uri="/"),
* @SLX\Bind(routeName="articleIndex")
* )
*/
public function index(Application $app)
{
$articles = R::findAll('article');
return $app['twig']->render('Article/index.twig', array(
'articles' => $articles,
));
}
/**
* @SLX\Route(
* @SLX\Request(method="GET", uri="{id}"),
* @SLX\Assert(variable="id", regex="\d+")
* )
*/
public function show(Application $app, $id)
{
$article = R::load('article',$id);
if($article->id == 0)
{
echo 'die';die();
}
return $app['twig']->render('Article/show.twig', array(
'article' => $article,
));
}
/**
* @SLX\Route(
* @SLX\Request(method="POST", uri="/")
* )
*/
public function store(Application $app, Request $request)
{
$article = R::dispense("article");
$article->nom = $request->get('nom');
$article->prix = $request->get('prix');
$id = R::store($article);
return $app->redirect('/Silex2/web/article/');
}
And my model :
<?php
namespace App\Models;
use RedBeanPHP\SimpleModel;
class Model_Article extends SimpleModel {
public function open() {
//global $lifeCycle;
//$lifeCycle .= "called open: ".$this->id;
}
public function dispense() {
//global $lifeCycle;
//$lifeCycle .= "called dispense() ".$this->bean;
}
public function update() {
if ($this->bean->prix >4)
throw new Exception( 'Trop cher!' );
}
public function after_update() {
//global $lifeCycle;
//$lifeCycle .= "called after_update() ".$this->bean;
}
public function delete() {
//global $lifeCycle;
$lifeCycle .= "called delete() ".$this->bean;
}
public function after_delete() {
//global $lifeCycle;
//$lifeCycle .= "called after_delete() ".$this->bean;
}
}
Does someone have an idea ? Thank you !
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+unsubscribe@googlegroups.com.
To post to this group, send email to redbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/redbeanorm.
For more options, visit https://groups.google.com/d/optout.