Model fuse-methods not working inside a namespace?.

Visto 25 veces
Saltar al primer mensaje no leído

Juan Ángel Celdrán

no leída,
27 ene 2017, 9:35:5527/1/17
a redbeanphp

Hi, I'm new to redbean so this may be a stupid question, but I can't figure out what is going wrong.

My application runs inside namespace "App". So I can invoke the "R" class methods by adding a backslash, like this:
 
$user = \R::dispense("user");

This works fine inside "App" or another namespace. But, when inside a namespace, model fuse-methods don't seem to work.

I am testing with the code below. The methods \R::dispenseAll and \R::store work fine whether the namespace is "App" or not. But, when it is "App" (or other)  then the fuse methods are not invoked. However, if the first line namespace App is commented, then everything works as expected.


Thanks in advanced.

<?php 
namespace App // if this line is commented, everything works as expected
{
require 'rb.php';

// setup
\R::setup("mysql:host=localhost;dbname=application", 'root', '');

// this doesn't work inside "App" namespace
class Model_Band extends \RedBean_SimpleModel 
{
public function update() 
{
echo __METHOD__,'<hr>';
if ( count( $this->bean->ownMember ) >4 ) 
throw new Exception( 'Too many members!' );
}
}

// test model-fuse methods
list( $band, $members ) = \R::dispenseAll( 'band,member*5' );
$band->ownMember = $members;
\R::store( $band ); // will trigger exception (not inside App namespace)
}


gabor

no leída,
27 ene 2017, 10:44:5027/1/17
a redbeanphp


Hi there,

You have to tell RedBeanPHP about the namespace you wish to use:

define'REDBEAN_MODEL_PREFIX''\\Model\\' )



also see:

http://www.redbeanphp.com/index.php?p=/models


cheers
Gabor
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos