Session handling

For programming and general questions on Zend Framework

Session handling

Postby mdiez00 on Fri Feb 03, 2012 9:02 pm

i am having a problem with session handling in zend. Whenever i set a new value(retrieved from GET) in the session the value is set correctly but when i take out name of the variable frm the url lin(GET) and do a zend_debug::dump on the session that session variable previously set comes back as the word "public".

Not sure what is happenning there. if anyone can help i would appreciate.

Thank you.
mdiez00
 
Posts: 5
Joined: Fri Feb 03, 2012 8:57 pm

Re: Session handling

Postby mkherlakian_zend on Fri Feb 03, 2012 10:10 pm

Hi, Could you please provide more info? What are the exact urls you are using? And also maybe some code to show how you are setting the variable and retrieving it fro session. Thanks!
User avatar
mkherlakian_zend
 
Posts: 88
Joined: Tue Jan 10, 2012 2:41 pm

Re: Session handling

Postby mdiez00 on Mon Feb 06, 2012 1:35 pm

hi there, here is the code you requested.the prblem is that after setting the variable in the session it comes back as th e word public where it should be an integer with a page number.
remember i am asetting the value thrgough GET.

thank you for your help.

<?php

class App_SecaoPaginator {


protected $ns;
protected $params = array();
protected $defaults = array(
'ordem' => 'TEMPO_TOTAL',
'page' => 1,
'itemsperpage' => 20,
'direcao' => 'ASC',
);


public function __construct ($ns, $defaults)
{
$this->ns = new Zend_Session_Namespace($ns);
$sessionVar = (array)$this->ns->getIterator();

$this->params = $this->ns->applySet('array_merge',$this->params,$sessionVar);



$request = Zend_Controller_Front::getInstance()->getRequest();
$this->params = Zend_Controller_Front::getInstance()->getRequest()->getParams();

/*if (!isset($this->ns->existFilter)) {
$this->defaults = array_merge($this->defaults,$defaults);
$this->params = array_merge($this->defaults,$this->params);
}
$this->params = array_merge($sessionVar,$this->params);
*/



$this->inicializar();
$this->ns->existFilter = true;
}

public function getSessionVars()
{
return array(
'ordem' => $this->ns->ordem,
'page' => $this->ns->page,
'itemsperpage' => $this->ns->itemsperpage,
'direcao' => $this->ns->direcao,
);
}

public function paginatorKey($key)
{
return array_key_exists($key, $this->defaults);
}

public function inicializar ()
{
//validar

foreach($this->params as $key=>$value)
{
if (array_key_exists($key, $this->defaults)) {
$metodo = 'set' . ucfirst($key);
$this->$metodo($value);
//$this->ns->$key = $value;
}
//$this->ns->$key = $value;
}
//$this->popularSessao();
}

public function popularSessao()
{
foreach($this->params as $key=>$value)
{
if (array_key_exists($key, $this->defaults)) {
$this->$key = $value;
}
}
$this->sessionVar = $this->ns->getIterator();
Zend_Debug::dump($this->sessionVar,'sessionVar');
}

/**
* @return the $page
*/
public function getPage ()
{
return $this->ns->page;
}

/**
* Retorna o nome da Coluna a ser ordenada
* @return the $ordem
*/
public function getOrdem ()
{
return $this->ns->ordem;
}

/**
* Retorna a direcao do ordenação.
* @return the $direcao
*/
public function getDirecao ()
{
return $this->ns->direcao;
}

/**
* retorna o número de item pra visualizar quantidades de linhas na página.
* @return the $itemsperpage
*/
public function getItemsperpage ()
{
return $this->ns->itemsperpage;
}

/**
* @param field_type $page
*/
public function setPage ($page)
{
$this->ns->page = $page;
}

/**
* @param field_type $ordem
*/
public function setOrdem ($ordem)
{

$this->ns->ordem = $ordem;
}

/**
* @param field_type $direcao
*/
public function setDirecao ($direcao)
{
if (!in_array(strtolower($direcao), array('asc','desc'))) {
throw new Exception('[' . __CLASS__ . '] direcao invalida');
}
$this->ns->direcao = $direcao;
}

/**
* @param field_type $itemsperpage
*/
public function setItemsperpage ($itemsperpage)
{
if (!in_array($itemsperpage, array(15,30,60,120,240))) {
throw new Exception('[' . __CLASS__ . '] Itens por pagina fora dos limites[15 - 240]');
}
$this->ns->itemsperpage = $itemsperpage;
}

}



?>
mdiez00
 
Posts: 5
Joined: Fri Feb 03, 2012 8:57 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 2 guests