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

buenas GatorV, nose si me puedes ayudar con este tema, ya que he visto que has contestado muchas respuestas de zendframework.

como puedo aplicar esta funcion?"function _load_all_artist()" sin usar Zend_tables ni nada de eso ("models). te paso la funcion, y mi estructura ok? a ver que opinas, ya que hace dias que me estoy peleando y no me sale :(. ( novato novato )

la funcion: quiero llamar a "private function _load_all_artist()" desde sumaAction()--) una funcion dentro de mi indexcontroller.php

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

        
$this->view->title "My Albums";

      
//  $album = new Album();
     //   $this->_load_all_artist();
       // $this->view->albums = _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;
        } 
y luego nose el suma.phtml como tendria que quedar... el que tengo ahora era usando Zend_tables
suma.phtml--)dentro de views/scripts/index/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'); ?>
te paso mi index.php por si quieres ver que falta algun modulo.los parametros de la BD lo hago con el config.ini (application/config.ini', 'general')

index.php
dentro de public.

Código PHP:
<?php
error_reporting
(E_ALL|E_STRICT);
date_default_timezone_set('Europe/London');
set_include_path('.' PATH_SEPARATOR '../library'
PATH_SEPARATOR '../application/models/'
PATH_SEPARATOR get_include_path());
include 
"../library/Zend/Loader.php";
Zend_Loader::loadClass('Zend_Controller_Front');

//El uso de Zend_Config es muy sencillo:
//$config = new Zend_Config_Ini('config.ini', 'section');
//controlaldors addicons per la BD config.ini arciu creat
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');


// load configuration
$config = new Zend_Config_Ini('../application/config.ini''general');
$registry Zend_Registry::getInstance();
$registry->set('config'$config);



// setup controller
$frontController Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setBaseUrl('/ZendFrame/public');
$frontController->setControllerDirectory('../application/controllers');

// setup database
$db Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);

// run!
$frontController->dispatch();
muchas gracias! a quien me pueda ayudar :p

Última edición por bellleti; 05/05/2009 a las 03:30 Razón: falta de cositas