Page 1 of 1
problem whith register
Posted: Tue Aug 28, 2007 4:11 am
by nahydy
hi
i'm using zend framework and i'm trying to use the register to save parameters. i wrote this code in my controllers :
Code: Select all
Zend::register('var','dddmm');
$var1=Zend::registry('var');
$this->view->message=$var1;
and when i tried to run my application i've got this error message:
Fatal error: Class 'Zend' not found in /var/www/test/pixels/application/controllers/IndexController.php on line 126
so i thought that may be in my function init i should add this
Code: Select all
Zend_Loader::loadClass('Zend_Registry');
but it still shows the same problems i dont' understand why it doesn't works. can you help me.
Posted: Tue Aug 28, 2007 4:27 am
by volka
Do you have
or
somewhere in your code?
Posted: Tue Aug 28, 2007 4:44 am
by nahydy
i checked in my code i didn't found this include. i added it and when i tried ti run again it seems that there's no such file.i looked into the zend framework files to make sure, and there is no such file. is that normal?
Posted: Tue Aug 28, 2007 4:47 am
by xpgeek
No it is not.
First you need setup Zend correctly before you start using it

.
Posted: Wed Aug 29, 2007 4:47 am
by nahydy
hi i downloaded the last release of Zend framework. Then i copied the library into my project. But it seems that there's no Zend.php. I'm little bit confused.

Posted: Wed Aug 29, 2007 5:48 am
by xpgeek
Start from manual
http://framework.zend.com/manual/en/ it can help you in many questions.
Posted: Wed Aug 29, 2007 12:04 pm
by RobertGonzalez
I don't have a Zend.php file in any of the versions of the Zend framework that I have.
In the few versions I have, it would appear that you would want to do something like:
Code: Select all
<?php
Zend_Registry::set('var','dddmm');
?>
Posted: Wed Aug 29, 2007 2:28 pm
by nahydy
thank you for your help in fact
Code: Select all
Zend_Registry::set('var','dddmm');
worked very well.
But i still have another problem. When i tested the set and the get i put all the code in one function so that i can see if my syntax do works. And it worked. But when i tried to use these two functions separately i've got the following problem: in my function getter_register, it can not recognize
Code: Select all
$this->tab_coords->get('coords_var')
.
Here the hole code:
Code: Select all
class caddie extends Zend_Registry
{
protected $tab_coords="";
function write_register($tab)
{
$this->tab_coords=$this->getInstance();
$this->tab_coords->set('coords_var',$tab);
}
function getter_register()
{
return $this->tab_coords->get('coords_var');
}
}
i thought that the register is accessible any where in my code. is there a problem in my code that i didn't see it?
Posted: Wed Aug 29, 2007 3:13 pm
by RobertGonzalez
You could try this:
Code: Select all
<?php
class caddie extends Zend_Registry
{
protected $tab_coords="";
function write_register($tab)
{
$this->tab_coords = parent::getInstance();
$this->tab_coords->set('coords_var',$tab);
}
function getter_register()
{
return $this->tab_coords->get('coords_var');
}
}
?>
Alternatively you could do:
Code: Select all
<?php
class caddie extends Zend_Registry
{
public static function write_register($tab)
{
parent::getInstance()->set('coords_var',$tab);
}
public static function getter_register()
{
return parent::getInstance()->get('coords_var');
}
}
?>
And you can use it like:
Code: Select all
<?php
$tab = 'FooBar';
caddie::write_register($tab);
echo caddie::getter_register();
?>
Posted: Thu Aug 30, 2007 2:55 am
by nahydy
hi i tried the solution that you proposed but it doesn't works. It shows me the following error message:
Strict Standards: Non-static method caddie::getter_register() should not be called statically, assuming $this from incompatible context in /var/www/test/pixels/application/controllers/IndexController.php on line 128
Fatal error: Uncaught exception 'Zend_Exception' with message 'No entry is registered for key 'coords_var'' in /var/www/test/pixels/library/Zend/Registry.php:145 Stack trace: #0 /var/www/test/pixels/application/models/caddie.php(35): Zend_Registry::get('coords_var') #1 /var/www/test/pixels/application/controllers/IndexController.php(128): caddie->getter_register() #2 /var/www/test/pixels/library/Zend/Controller/Action.php(497): IndexController->formulaireAction() #3 /var/www/test/pixels/library/Zend/Controller/Dispatcher/Standard.php(230): Zend_Controller_Action->dispatch('formulaireActio...') #4 /var/www/test/pixels/library/Zend/Controller/Front.php(889): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 /var/www/test/pixels/index.php(39): Zend_Controller_Front->dispatch() #6 {main} thrown in /var/www/test/pixels/library/Zend/Registry.php on line 145
any idea?
Posted: Thu Aug 30, 2007 3:08 am
by nahydy
ok for
Strict Standards: Non-static method caddie::getter_register() should not be called statically, assuming $this from incompatible context in /var/www/test/pixels/application/controllers/IndexController.php on line 128
it was obious i missed to put declare my function public static. But i still have the same problem.

Posted: Thu Aug 30, 2007 10:54 am
by RobertGonzalez
Here's a clean stack trace so you can see what is happening:
Fatal error: Uncaught exception 'Zend_Exception' with message 'No entry is registered for key 'coords_var'' in /var/www/test/pixels/library/Zend/Registry.php:145
Stack trace:
#0 /var/www/test/pixels/application/models/caddie.php(35): Zend_Registry::get('coords_var')
#1 /var/www/test/pixels/application/controllers/IndexController.php(128): caddie->getter_register()
#2 /var/www/test/pixels/library/Zend/Controller/Action.php(497): IndexController->formulaireAction()
#3 /var/www/test/pixels/library/Zend/Controller/Dispatcher/Standard.php(230): Zend_Controller_Action->dispatch('formulaireActio...')
#4 /var/www/test/pixels/library/Zend/Controller/Front.php(889): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 /var/www/test/pixels/index.php(39): Zend_Controller_Front->dispatch()
#6 {main} thrown in /var/www/test/pixels/library/Zend/Registry.php on line 145
What are you trying to do with your app? Why do you need to extend the Zend registry?
Posted: Fri Aug 31, 2007 4:29 am
by nahydy
what i'm trying to do is to save an array in my register. So i created a class which can set my array in a register. And through my controllers i will access to this register. In my controllers i did this:
Code: Select all
class IndexController extends Zend_Controller_Action
{
function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
Zend_Loader::loadClass('caddie');
}
function indexAction()
{
$this->view->title = "Mespixels";
$this->view->baseUrl=$this->_request->getBaseUrl();
}
function formulaireAction()
{
$this->view->title = "formulaire d'inscription";
if ($this->_request->isPost())
{
$res=$this->_request->getPost('tabs_coords');
$fields= explode(',',$res);
caddie::write_register($fields);
$this->render();
}
}
function supprimerAction()
{
$this->view->title = "Supprimer un album";
$this->view->baseUrl=$this->_request->getBaseUrl();
$this->view->message=caddie::getter_register();
$this->render();
}
}
My two functions works well if i used them in my formulaireAction but when i tried to get the value stored in my register through my supprimerAction here i've got the error message . the aim of using my register is to be accessible anywhere in my code application. i don't understand why it doesn't works like this? can you help me.
Posted: Fri Aug 31, 2007 9:15 am
by Begby
You must call caddie::write_register() before you call caddie::getter_register() otherwise you are going to get that error.
The problem is that when the supprimerAction() method gets called the formulaireAction() method is not getting called before it. This is because only one controller action is getting called on each page load in your framework, which is how it is usually supposed to work unless you are using _forward() or some fancy routing.
If you are trying to get the variable to stick around between pages, then you don't want to use Zend_Registry, you want to use Zend_Session to set and retrieve the value.