Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/05/2009, 04:50
bellleti
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años
Puntos: 1
Pregunta consulta con zendframework sin "models"

Por empezar decir que soy muy novato, y acabo de empezar con el zend.
buenas me gustaria saber como hacer consultas, sin tener que utilizar la clase models, ahora lo hago con el siguiente ejemplo y me gustaria poder hacer y manejar los querys, y passar variables en las consultas.

mi ejemplo:
estamos en el indexcontroller, con la funcion suma,que quiero hacer una consultas a la bD
por lo tanto mi direcion public/index/suma

mi duda:
tengo esta funcion que muestra todos los artistas de la base dedatos, ahora esta comentado lo que si me funciona. El album.php que esta en la carpeta models, me gustaria no usarlo, y hacerlo con la funcion de más abajo"load_all_artist", como lo haria? y como la llamo desde la funcion sumaAction? luego para recojerlo en suma.phtml.... pongo mas abajo nose si estaria bien, gracias

Código PHP:
function sumaAction()
    {
    $this->view->title = "Suma actions: consulta BD";

        /*en lugar de usar esta clase que tengo en models"album.php",
         usar la funcion de más abajo,load_all_artist()
         _______________________
          "album.php" ......
            <?php
            
class Album extends Zend_Db_Table
                    
{
                    protected 
$_name 'album';
                    }
        
_______________________
        
        $this
->view->title "My Albums";
        
$album = new Album();
        
$this->view->albums $album->fetchAll();
        */
    
//aqui llamariamos a la funcion load_all_artist
    //$this->view->load_all_artist();



    
$this->render();

    }
    private function 
load_all_artist() {
            
$query  "SELECT * FROM Album ";
            
$query .= " WHERE active='1' ";

            
$result mysql_query($query);
            if (!
$result) {
                
error_log("Loading All Category: " mysql_error());
            } else {
                
$results = array();
                while (
$row mysql_fetch_assoc($result)) {
                    
$line = array();
                    
$line['title'] = $row['title'];
                    
$line['artist'] = $row['artist'];
                    
$line['actiu'] = $row['active'];
                    
//$line['link'] = '/browse/category/?id=' . $row['id'];

                    
$results[] = $line;
                }
            }

            return 
$results;
        }


mi suma.phtml

Código PHP:

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->escape($this->title); ?></h1>
<p><a href="<?php echo $this->baseUrl?>/index/add">Add new album</a></p>
<p><a href="<?php echo $this->baseUrl?>/index/delete">Delete album</a></p>
<p><a href="<?php echo $this->baseUrl?>/index/edit">Edit new album</a></p>
<p><a href="<?php echo $this->baseUrl?>/index/suma">PaginaprovaBD</a></p>
<table>
<tr>
<th>Title</th>
<th>Artist</th>
<th>active</th>
<th>&nbsp;</th>
</tr>
<?php foreach($this->albums as $album) : ?>
<tr>
<td><?php echo $this->escape($album->title);?></td>
<td><?php echo $this->escape($album->artist);?></td>
<td><?php echo $this->escape($album->active);?></td>
<td>
<a href="<?php echo $this->baseUrl?>/index/edit/id/<?php
echo $album->id;?>">Edit</a>
<a href="<?php echo $this->baseUrl?>/index/delete/id/<?php
echo $album->id;?>">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $this->render('footer.phtml'); ?>
muchas gracias!

Última edición por bellleti; 02/05/2009 a las 04:54 Razón: falta de cosillass