Re: RedBeans don't FUSE with model

37 views
Skip to first unread message

gabor de mooij

unread,
Dec 28, 2016, 12:46:35 PM12/28/16
to redbe...@googlegroups.com
Have you tried it without the framework, maybe something is interfering..

Just tested locally, over here this works fine:

use RedBeanPHP\SimpleModel;

<?php
require 'rb.php';

R::setup();

class Model_Book extends SimpleModel {
        public function update() {
                die('UPDATING');
        }
}

R::store(R::dispense('book'));
exit;


it correctly displays:

UPDATING



cheers
Gabor




On Mon, Dec 26, 2016 at 5:26 PM, Peter Artoung <pete...@hotmail.fr> wrote:

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.

Reply all
Reply to author
Forward
0 new messages