How to make a view that interacts using multiple models
Hello guys from the community. This is my first post (well, it's a question anyways) since I joined the group because I'm very new to this amazing framework. Please sorry if my English is far from being perfect, I'm trying to do my best even if it's not my native language. (I'm from Chile, Latin America) Well this is the thing: I'm making small invoice system. I already made my small database design (which can be seen in the image below), models and their associations, default controllers and views (using the cake bake script). I tried to follow ALL the cakePHP conventions and rules to make myself the things easier and it seems it worked. a href=http://imgur.com/AqIAq.png; title=Hosted by imgur.comhttp://imgur.com/AqIAq.png/a http://imgur.com/AqIAq.png (direct link if the html link doesn't works) My problem is that I can't find how to make a view (for the index action) where I could have and handle this information: - Invoice number (numeroFactura into facturas table) - Invoice date (fecha into facturas table) - Rut (rut inro clientes table) - Names (nombres into clientes table) - Last names (apellidos into clientes table) - Product name (descripcion into productos table) - Product quantity (cantidad into lineas table, lineas table is for the invoice lines) - Product value (precio ino productos table) Should I make this view customizing the lineas_facturas default view for the index action? or .. Can I even make the view I need customizing the facturas or lineas default view for the index action? Maybe using some kind of tricky code to relate the models I need to get the data from? Thanks in advance people, I'm still a newbie but I don't give up! Even if I have to read in English being an Spanish language native guy, this framework worth it! Greetings from Chile! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to make a view that interacts using multiple models
Hola, Como va??? Yo soy de Argentina. Espero que sea esto lo que estabas buscando, sino contame en español lo que necesitas y veo si te puedo dar una mano. El único problema que tuve con una consulta similar a esta es que no la pude ordenar por todos los campos, y no encontré como hacer eso por ahora, pero el listado me lo hizo OK. function index() { $this-Factura-recursive = 0; $this-paginate = array( 'Factura' = array( 'joins' = array( array( 'table' = 'clientes', 'alias' = 'Cliente', 'type' = 'inner', 'conditions' = array( 'Factura.cliente_id = Cliente.id' ) ), array( 'table' = 'lineas_facturas', 'alias' = 'LineasFactura', 'type' = 'inner', 'conditions' = array( 'Factura.id = LineasFactura.factura_id' ) ), array( 'table' = 'lineas', 'alias' = 'Linea', 'type' = 'inner', 'conditions' = array( 'Linea.id = LineasFactura.linea_id' ) ), array( 'table' = 'productos', 'alias' = 'Producto', 'type' = 'inner', 'conditions' = array( 'Linea.producto_id = Producto.id' ) ) ), 'fields' = array('Factura.numeroFactura', 'Factura.fecha', 'Cliente.rut', 'Cliente.apellidos', 'Cliente.nombres', 'Producto.descripcion', 'Linea.cantidad', 'Producto.precio') ) ); $data = $this-paginate('Factura'); $this-set('facturas', $data); } Saludos Notinyes PD: Acá te mandé el paginate, pero un find sería bastante similar. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to make a view that interacts using multiple models
On Apr 20, 3:34 am, Pablo Vergara B. pabloandre...@gmail.com wrote: Well this is the thing: I'm making small invoice system. I already made my small database design (which can be seen in the image below), models and their associations, default controllers and views (using the cake bake script). I tried to follow ALL the cakePHP conventions and rules to make myself the things easier and it seems it worked. a href=http://imgur.com/AqIAq.png; title=Hosted by imgur.comhttp://imgur.com/AqIAq.png/a http://imgur.com/AqIAq.png(direct link if the html link doesn't works) As I understand the question, this is the view for FacturasController::index. So, you want to display a list of invoices, along with the Product name and the Client details. So, if your associations are all correct, you should be able to do a find('all') from Factura and it will pull in the Linea, Product, and Client details. Try setting 'recursive' to 2 and see what it returns. Even better, use ContainableBehavior: $this-set( 'data', $this-Factura-find( 'all', 'contain' = array( 'Linea' = array( 'Product' ), 'Cliente' ) ) ); I think that should work. Make sure to add Containable to the Facturs model's $actsAs array (or to AppModel's to make it available everywhere). Add debug($data) at the top of your view to see the array structure. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en