Foros del Web » Programando para Internet » PHP » Zend »

ayuda cositas en zendframework

Estas en el tema de ayuda cositas en zendframework en el foro de Zend en Foros del Web. buenas estava mirando un codigo en zend.framework y tengo algunas dudas... PRIMERA $ticket['subcategory_id'] = var_from_post('subcategory_id_' . $ticket['category_id']); que hace referencia el punto que une subcategory_id ...
  #1 (permalink)  
Antiguo 07/05/2009, 10:55
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años
Puntos: 1
Pregunta ayuda cositas en zendframework

buenas estava mirando un codigo en zend.framework y tengo algunas dudas...

PRIMERA
$ticket['subcategory_id'] = var_from_post('subcategory_id_' . $ticket['category_id']);
que hace referencia el punto que une subcategory_id i $ticket['category_id..???

SEGUNDA
supongamos que tenemos 2, deplegables, como se hace en zendFramework que cuando un usuario elija el del primero, varien los del segundo desplegando segun la eleccion? o sea tendria que mandar esta variable y luego... cargar en el segundo desplegable... pero sin actualizar la pagina... mmmm quiza javascript? o zendframework se hace distintto?

pongo el codigo de mi phtml

Código PHP:
<select id="id0" name="artist">
        <?php foreach($this->albumss as $album) : ?>
    <option value="<?php $album['id'];?>"><?php echo $album['artist'];?></option>
<?php endforeach; ?>
</select></td>
  <td>
<select id="id1" name="Title">
        <?php foreach($this->albumss as $album) : ?>
    <option value="<?php $album['id'];?>"><?php echo $album['title'];?></option>
<?php endforeach; ?>
</td>
</tr>
</select>
  #2 (permalink)  
Antiguo 07/05/2009, 12:18
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: ayuda cositas en zendframework

Tu primera duda no la entiendo, para tu segunda duda tienes que usar AJAX, haces un request a un action de tu controller que te traiga los datos de tu combo dependiente.

Saludos.
  #3 (permalink)  
Antiguo 07/05/2009, 12:41
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años
Puntos: 1
Respuesta: ayuda cositas en zendframework

Cita:
Iniciado por GatorV Ver Mensaje
Tu primera duda no la entiendo, para tu segunda duda tienes que usar AJAX, haces un request a un action de tu controller que te traiga los datos de tu combo dependiente.

Saludos.
Buenas GatorV! todo bien? un saludo!

pues... ya veo que tambien tendre k aprender ajax,!!!

la segunda duda es que hace esta instruccion...


$ticket['subcategory_id'] = var_from_post('subcategory_id_' . $ticket['category_id']);

asignamos a $ticket['subcategory_id'], las variables que provienen de post ?? esas 2?? subcategory_id_' . $ticket['category_id'] yo pedia por el numero que une las 2...

me entiendes??

gracias GaTORv!

PD: alguna otra forma de hacer lo de los dos desplegables sin ajax??

Un saludo!

Última edición por bellleti; 07/05/2009 a las 13:10
  #4 (permalink)  
Antiguo 07/05/2009, 13:52
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: ayuda cositas en zendframework

Los desplegables no, es forzoso su uso a menos que quieras recargar toda la pagina para volver a dibujar los selects, es mas complicado por eso se recomienda usar AJAX.

Desconozco que hace la funcion var_from_post, donde la viste definida? En Zend Framework, casi siempre (si estas dentro del controlador) es $this->_getParam('var', 1);

Saludos.
  #5 (permalink)  
Antiguo 07/05/2009, 14:14
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años
Puntos: 1
De acuerdo Respuesta: ayuda cositas en zendframework

buenas gatorV, pues esta funcion la encontre en una pagina que tengo que actualizar, creo que lo utiliza para recuperar las variables del formulario de contacto:

te paso el controlador i el phtml. i me das tu opinion

Código PHP:
public function indexAction() {
            
$this->_redirect("contact/eticket_new");
        }

        public function 
eticketnewAction() {
            
Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
            
$view $this->view;

            
$ticket = array();
            
$vars = array('category_id''question''name''email');
            foreach (
$vars as $var) {
                
$ticket[$var] = var_from_post($var);
            }
            
$ticket['subcategory_id'] = var_from_post('subcategory_id_' $ticket['category_id']);

            if (!
is_numeric($ticket['category_id'])) {
                
$this->first_time_show($view);
                return;
            }

            
// if not first time, check values for correctness
            
$messages = array();
            if (!
is_numeric($ticket['category_id']) || $ticket['category_id'] < 1) {
                
$messages[] = "Please choose a category";
            }

            if (!
is_numeric($ticket['subcategory_id']) || $ticket['subcategory_id'] < 1) {
                
$messages[] = "Please choose a subcategory";
            }

            if (empty(
$ticket['question'])) {
                
$messages[] = "Please write a question";
            }

            if (empty(
$ticket['name'])) {
                
$messages[] = "Please write your name";
            }

            if (empty(
$ticket['email'])) {
                
$messages[] = "Please write your email";
            }

            
$seccode var_from_post("seccode");
            if (empty(
$seccode)) {
                
$messages[] = "Please write the spam control text";
            } else {
                
$seccode_real var_from_session('captcha_neweticket');
                unset(
$_SESSION['captcha_neweticket']);
                if (
strtoupper($seccode) != strtoupper($seccode_real)) {
                    
$messages[] = "The spam control text was not correct";
                }
            }

            
// if errors reshow form
            
if (!empty($messages)) {
                
$this->any_time_show($view$ticket$messages);
                return;
            } else {
                
// save
                
try {
                    
$ticket['code'] = "SUPPORT" $this->eticket_code_unique();
                    
$this->save_new_ticket($ticket);

                    
// send mail
                    
$this->eticket_new_sendmail($ticket);

                    
// redirect to OK page
                    
header("Location: " "/contact/eticket_new_thanks?code=" $ticket['code']);
                    die();
                } catch (
Exception $e) {
                    
error_log("Saving new ticket: " $e->getMessage());

                    
$messages[] = "Problem saving ticket, please try again in a few minutes";
                    
$this->any_time_show($view$ticket$messages);
                }
            }
        } 
phtml.
Código PHP:
<?php
    
if (isset($this->messages)) {
        foreach(
$this->messages as $message) {
?>
<span style="color: red; font-weight: bold;"><?=$this->translate($message)?></span>
<br/>
<?php    ?>
<br/>
<?php
    
}
?>

<style>
#neweticket th {
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
</style>    

<form method=post action="?">

<table id="neweticket">
  <tr>
    <th><?=$this->translate("Category:")?></th>
    <td>
<select id="category_id" name="category_id">
    <option value="0"> --- </option>
    <?php foreach ($this->categories as $item) { ?>
    <option value="<?=$item['id']?>"
        <?php if ($item['id'] == $this->category_id) { ?> selected="selected" <?php ?>
        ><?=$item['title']?></option>
    <?php }?>
</select>
    </td>
  </tr>
  <tr>
    <th><?=$this->translate("Subcategory:")?></th>
    <td>
<select id="subcategory_id_0" name="subcategory_id_0" style="display: none;">
    <option value="0">  --- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
</select>
<?php foreach ($this->categories as $item) { ?>
<select id="subcategory_id_<?=$item['id']?>" name="subcategory_id_<?=$item['id']?>" style="display: none;">
    <option value="0">  --- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <?php foreach ($item['subcategories'] as $item2) { ?>
    <option value="<?=$item2['id']?>"
        <?php if ($item2['id'] == $this->subcategory_id) { ?> selected="selected" <?php ?>
        ><?=$item2['title']?></option>
    <?php }?>
</select>
<?php }?>
    </td>
  </tr>
  <tr>
    <th><?=$this->translate("Question:")?></th>
    <td><textarea name="question" style="width:483px;align:center;" rows="7"><?=$this->question?></textarea></td>
  </tr>
  <tr>
    <th><?=$this->translate("Name:")?></th>
    <td><input class="input-text" type=text name="name" size=45 value="<?=$this->name?>"></td>
  </tr>
  <tr>
    <th><?=$this->translate("Email:")?></th>
    <td><input class="input-text" type=text size=45 name="email" value="<?=$this->email?>"></td>
  </tr>
  <tr>
    <th><?=$this->translate("Spam control:")?></th>
    <td>
<?=$this->translate("In order to prevent spam, please copy the text shown in the image in the box below:")?>

<table>
<tr><td><img id="security_code_image" src="<?=$this->captcha?>" style="border: 1px solid #8888ff;"/></td></tr>
<tr>
    <td><input id="seccode" type="text" name="seccode" maxlength="6" style="letter-spacing: 5px;"></td>
</tr>
</table>
    </td>
  </tr>
  <tr>
    <th></th>
    <td><input type=submit value="<?=$this->translate("Send question")?>" style="font-weight: bold;"></td>
  </tr>
  <tr>
    <th></th>
    <td></td>
  </tr>
</table>


<script type="text/javascript">
category_id_previous = $("#category_id").val();
$("#subcategory_id_" + $("#category_id").val()).show();
$("#category_id").change(function() {
    $("#subcategory_id_" + category_id_previous).hide();
    $("#subcategory_id_" + $("#category_id").val()).show();
    category_id_previous = $("#category_id").val();
});
</script>


</form>
un saludo, ya me diras..... tu opinion :P
  #6 (permalink)  
Antiguo 07/05/2009, 14:36
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: ayuda cositas en zendframework

Pues es probable que la hayan definido solo para tu aplicacion aunque es la forma incorrecta de hacerlo.

Saludos.
  #7 (permalink)  
Antiguo 09/05/2009, 10:06
Avatar de mstekl  
Fecha de Ingreso: mayo-2009
Ubicación: Solymar, Uruguay
Mensajes: 5
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: ayuda cositas en zendframework

Hola, no conozco exactamente qué es lo que hace la función esa, pero por lo el nombre me da la sensacion que saca las variables del $_POST y probablemente las sanitiza.

Por ejemplo en la linea que pones, supongamos que el valor de $ticket['category_id'] sea 4... está asignando a $ticket['subcategory_id'] el valor de $_POST['subcategory_id_4']

El operador del punto lo que hace es unir dos cadenas de texto, por ejemplo
$nombre = "juan";
echo "Hola ".$nombre; // esto manda a pantalla el texto "Hola Juan"

Espero que sirva de ayuda.
Saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:43.