PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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?
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.
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
<?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');
}
}
?>
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
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.
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:
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.
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.