He creado un método en el modelo Nivele (tabla niveles)
Código:
  
Este modelo Nivele  está relacionado con otro modelo llamado Juego (Juego has many Niveles y Niveles BelongsTo Juego )class Nivele extends AppModel {
    var $name = 'Nivele';
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Juego' => array(
            'className' => 'Juego',
            'foreignKey' => 'juego_id' ) );
    var $hasMany = array(
        'partidas' => array(
            'className' => 'partidas',
            'foreignKey' => 'nivele_id',
            'dependent' => false       ) );
function nivelMayor($juego_id) {
    if (empty($juego_id))
    return false;
      $nivel=$this->Nivele->field('Numero_Nivel',array('juego_id' =>$juego_id)); (línea que tira el error)
                                                      
    if (!$nivel)
    return false;
    else {
    $this->Session->setFlash(__('Nivele número '. $nivel, true));
        $this->redirect(array('action'=>'index'));
    }}
function cualesMayor($juego_id,$numero_nivel) {
    $mayor=NivelMayor($juego_id);
    if ($numero_nivel >$mayor ) {
    $this->Nivele->User->activar($id=null,4) ; //estado para juego finalizado
    return true;
    }
    return $numero_nivel;
    }
}
Modelo Juego
Código:
  
En juegos_controller tengo este sencillo método que llama al método anteriormente creado en Nivele (aquí está el problema):class Juego extends AppModel {
	var $name = 'Juego';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $hasMany = array(
		'Nivele' => array(
			'className' => 'Nivele',
			'foreignKey' => 'juego_id',
			'dependent' => false
			
		));
}
Código:
  
Como ambos modelos (nivele y juego) están relacionados no he creído conveniente usar  var $uses=array('Nivele','Juego') (aún así he probado y tampoco funciona);function ajugar($user_id,$juego_id,$numero_nivel) {
   
    $mayor=$this->Juego->Nivele->nivelMayor($juego_id);
    $this->redirect(array('action'=>'index'));
   
    }
El error que me tira es el siguiente:
Undefined property: Nivele::$Nivele [APP\models\nivele.php, line 36]
Fatal error: Call to a member function field() on a non-object in C:\xampp\htdocs\tests\app\models\nivele.php on line 36
Agradecería si alguien me puede echar un cable porque llevo horas rompiéndome la sesera y no se donde esta el fallo.
Mil gracias a tod@s de antemano.
 
 


 
 
 
 

