cake-php
[Arriba] [Todas las Listas]

El Problema relacionado para salvar modelos múltiples en un controlador

To: cake-php@xxxxxxxxxxxxxxxx
Subject: El Problema relacionado para salvar modelos múltiples en un controlador
From: Malintha Adikari <malintha.adikari@xxxxxxxxx>
Date: Sun, 23 Jun 2013 07:48:41 -0700 (PDT)
Delivery-date: Tue, 25 Jun 2013 11:10:14 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=fR5kUXV9AmCcTodi+te+GvbzUaCI4JKxGSVqRVcW2dk=; b=QY7JK3H8eZdOVKEmnDsz0cta5qSrUSZ+j1rqghntXnWkSqAuh9YxKduWDVlL1AoD+o OI0H5cXUSd/3fZMTaVR+xsN7XW0DsP2GrZsNwHSv117l87goMvDfZoeAp/9tscW3J5r/ 2rzt30H36XhI+OWoZy9J92qcjaZwvNKcnr78TKNg7baybqs7oFzL08LHAyCHOF9gzQJU 6K19dVKZU1QDZTEYyXztGoMCSjHAQMV7kRzEhyXWbrdrFRci8+lvETWi9aNXbr2s72MS gf/7BOk8VJIoFhDK3mi+kLPHdDmGtDKCBuV4Mh5MPx25XMi4r1/sY7lxF8h63uwKynKo bcFg==
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-beenthere:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=fR5kUXV9AmCcTodi+te+GvbzUaCI4JKxGSVqRVcW2dk=; b=T2QfU4l/0AZsDN81aKndSgiJ0sENofmeakuBPQ+LoAbFsovsp5yGe9ycA3R+B4iqzf ZvoSI1XnSDImgvpHsB+5v0NZbCwlfgsWzAW8+yeC6NMW0s19VBXnsp61Giv393XWGA4W HD6/hjlIGeea/Y2HCwvlFOIOMHJ25Z3Ig2ticMVCT6aaozs2jPwMIty1cIzZlT6qNbGN QTu8PirX7L1ohUAXTIFIYPNCVgoHQae/ExThgLGJNcCSKv/gYQEtgwxXT2Y0sgNo+8rl +OKJ971jDl+8xS+4ja+OEzJZak3t4k5v1L/qWGlwEXv8Gc+iyVgvZt+ZoE4aCN1MpHkb Utew==
Envelope-to: traductor@xxxxxxxxxxx
List-archive: <http://groups.google.com/group/cake-php>
List-help: <http://groups.google.com/support/>, <mailto:cake-php+help@googlegroups.com>
List-id: <cake-php.googlegroups.com>
List-post: <http://groups.google.com/group/cake-php/post>, <mailto:cake-php@googlegroups.com>
List-subscribe: <http://groups.google.com/group/cake-php/subscribe>, <mailto:cake-php+subscribe@googlegroups.com>
List-unsubscribe: <http://groups.google.com/group/cake-php/subscribe>, <mailto:googlegroups-manage+1003367825667+unsubscribe@googlegroups.com>
Mailing-list: list cake-php@xxxxxxxxxxxxxxxx; contact cake-php+owners@xxxxxxxxxxxxxxxx
Reply-to: cake-php@xxxxxxxxxxxxxxxx
Sender: cake-php@xxxxxxxxxxxxxxxx
*Hi,

soy un estudiante que está participando *GSOC 2013. Estoy haciendo proyecto con *cakephp. 
Quiero salvar dos modelos en el controlador mismo pero yo soy *stucked en 
el *middle de aquello. Te #poder complacer ayudarme para solucionar aquel problema.

Tengo dos mesas

1. Tarea- > *id, nombre, descripción, coste
2. Conecta-> *id, tarea_*id,conecta_*id  (aquí tarea_*id es *foriegn llave)

Código:    

//Tarea.*php

<?*php

/**
 * 
 */
Tarea de clase extiende *AppModel
    
    #unknown{^*var $nombre='Tarea';
    *var $*hasMany = variedad('Conecta');
}

?>

//Conecta.*php

<?*php

/**
 * 
 */
La Clase Conecta extiende *AppModel
    
    #unknown{^*var $nombre='Conecta';
    *var $*belongsTo =variedad( 'Tarea');
}

?>
    
//*TasksController.*php

<?*php
Clase *TasksController extiende *AppController

    #adj_nom $#público = 'Tareas';
    *var $variedad = de usos('Conecta','Tarea');
    función *creat_tarea()
        //$#prn -> *loadModel('Conecta');
        
        si (!Vacío($esto -> petición -> dato))
            $#nom = $esto -> Tarea -> salvar($esto -> petición -> dato);
            
            $esto -> petición -> dato['Conecta']['tarea_*id'] = $esto -> Tarea 
-> *id;
            $esto -> Sesión -> *setFlash($esto -> Tarea -> *id);
            $esto -> Tarea -> Conectar -> salvar($esto -> petición -> dato);
            //$*id = $esto -> Tarea -> Conectar -> *getLastInsertId();
            $esto -> redirigir(variedad('acción' => '*creat_tarea'));
            // depura($esto->petición->dato);

        }

    }


  //*creat_tarea.*ctp


<?*php
Repite $esto->Forma->crear('tarea');
?>

<*hr/>
<*h1>Tarea</*h1>
<*hr/>

<?*php
Repite $esto->Forma->entrada('Tarea.Nombre', variedad('etiqueta' => "Nombre"));
eco $esto->Forma->entrada('Tarea.Descripción', variedad('etiqueta' => 
"Descripción"));
eco $esto->Forma->entrada('Tarea.Coste', variedad('etiqueta' => "Coste"));
?>

<*hr/>
<*h1>Tarea Conectada</*h1>
<*hr/>

eco $esto->Forma->entrada('Conecta.Conectar_*id', variedad('etiqueta' => "Coste"));

<?*php Repite $esto->Forma->fin('Entrega'); ?>  
   

==========================================================================================

Cuándo  intento salvarlo da seguir Error


*de error: * la Llamada a una función de miembro salva() en un no-objeto


en línea "     $esto -> Tarea -> Conectar -> salvar($esto -> petición -> dato);  "
 

Qué es la razón para esto ?

-- 
Gustarnos en *FaceBook *https://www.facebook.com/*CakePHP
nos Encuentra en *Twitter *http://*twitter.*com/*CakePHP

--- 
Recibiste este mensaje porque eres *subscribed al *Google Grupos "*CakePHP" grupo.
A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un *email a pastel-*php+unsubscribe@xxxxxxxxxxxxxxxx.
A correo a este grupo, envía *email a pastel-php@xxxxxxxxxxxxxxxx.
Visita este grupo en *http://grupos.*google.*com/Pastel/de grupo-*php.
Para más opciones, visita *https://grupos.*google.*com/Los Grupos/optan_fuera.


Hi,

I am a student who is participating GSOC 2013. I am doing project with 
cakephp. I want to save two models in same controller but I am stucked in 
the middle of that. Could you please help me to solve that problem.

I have two tables

1. Task- > id, name, description, cost
2. Connect-> id, task_id,connect_id  (here task_id is foriegn key)

Code:    

//Task.php

<?php

/**
 * 
 */
class Task extends AppModel {
    
    var $name='Task';
    var $hasMany = array('Connect');
}

?>

//Connect.php

<?php

/**
 * 
 */
class Connect extends AppModel {
    
    var $name='Connect';
    var $belongsTo =array( 'Task');
}

?>
    
//TasksController.php

<?php
class TasksController extends AppController {

    public $name = 'Tasks';
    var $uses = array('Connect','Task');
    function creat_task() {
        //$this -> loadModel('Connect');
        
        if (!empty($this -> request -> data)) {
            $task = $this -> Task -> save($this -> request -> data);
            
            $this -> request -> data['Connect']['task_id'] = $this -> Task 
-> id;
            $this -> Session -> setFlash($this -> Task -> id);
            $this -> Task -> Connect -> save($this -> request -> data);
            //$id = $this -> Task -> Connect -> getLastInsertId();
            $this -> redirect(array('action' => 'creat_task'));
            // debug($this->request->data);

        }

    }


  //creat_task.ctp


<?php
echo $this->Form->create('task');
?>

<hr/>
<h1>Task</h1>
<hr/>

<?php
echo $this->Form->input('Task.name', array('label' => "Name"));
echo $this->Form->input('Task.description', array('label' => 
"Description"));
echo $this->Form->input('Task.cost', array('label' => "Cost"));
?>

<hr/>
<h1>Connected Task</h1>
<hr/>

echo $this->Form->input('Connect.connect_id', array('label' => "Cost"));

<?php echo $this->Form->end('Submit'); ?>  
   

==========================================================================================

When  I try to save it gives following error


*Error: * Call to a member function save() on a non-object


in line "     $this -> Task -> Connect -> save($this -> request -> data);  "
 

What is the reason for this ?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to cake-php@xxxxxxxxxxxxxxxx.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


<Anterior por Tema] Tema Actual [Siguiente por Tema>
  • El Problema relacionado para salvar modelos múltiples en un controlador, Malintha Adikari <=