|
||||
|
Hi Elemental, i didn't tried ro reproduce exactly your error, but i did this:
in the bootstrap directly (no in a fuction, but directly in the bootstrap) I setted an array: PHP Code:
PHP Code:
PHP Code:
Code:
Array ( [1] => 0 [2] => 2 [3] => 4 ) Cheers! |
|
||||
|
I use them in the same controller. So basically its a identity verification thingy.
In one action I get the username and password, and create a hash that is emailed to the user. I need to store the username/password/userid (a key in the table)/hash. I think I figured out I was doing this all wrong for my purposes. I've since put it in the session namespace and all is working out fine now. However, I'd still like to find out why it wasn't working as I may need to register arrays in the future. so, class myController extends Zend_Controller_Action () { public function startAction () { $params = $this->_request->getParams('post'); $regInfo = array ( 'id' = params['id'], 'uname' = params['username'], 'pass' = params['password'], 'vcode' = null, ); $regInfo['vcode'] = md5($reginfo['id'] . $reginfo['password']); //now I need to store this in the registry so I can refer to it later Zend_Registry::set('regInfo', $regInfo); //this works $test = Zend_Registry::get('regInfo'); } public function stopAction () { //this doesn't $test = Zend_Registry::get('regInfo'); } } stopAction throws an exception saying that there is no registered key 'regInfo' Now, that's not how I am doing my authentication stuff anymore so its not a pressing issue. However, I would like to be set arrays to the registry in one action and recall them in another action within the same controller. Maybe I am not understanding how the registry handles non-objects? Thanks for the reply and sorry for my horrid spelling... made me cringe to read it again, lol. |
|
||||
|
Hi Elemental!
Well, I tried to do something like you. I setted the array in an action, and requested it in another action of the same controller. To the meanings of this example i created an one-index-dumby-array, storing a md5 of a string. PHP Code:
PHP Code:
PHP Code:
Code:
Array ( [hola] => 4d186321c1a7f0f354b297e8914ab240 ) PHP Code:
May be you need get a closer look to your code, and doublecheck it, just in case... Cheers, and you forgive me for my bad english |
|
|||
|
Hi matias.quaglia,
I am a newbie in Zend Framework and I am facing the same problem with Elemental. Does the init() place in same controller class with the indexAction() in your example. ? If so, the registry must work, because init() would be called before the action(). thus, we place the registry::set() in the init() then each action() can access that registry value. Q1) Can I place the registry::set() outside the init() (e.g. set registry in indexAction() and get by testAction() ) ? Q2) How can I access that registred value in another controller class ? Is it possible ? thank you ~ Last edited by GeniusTse : 08-15-2007 at 02:34 AM. |
|
||||
|
You can do Zend_Registry::set() anywhere and Zend_Registry::get() anywhere. I'm not sure what was causing the issue I had before, but I am setting and getting arrays in other aspects of my app. Best example would be the config.xml. In my bootstrap I read in the config.xml via Zend_Config_Xml and put it in the registry. Then I retrieve it in a controller to setup a database connection or retrieve environment config settings.
The registry acts like a global varbiable store house so where you set and get don't matter, so long as your not trying to get something that hasn't been set... If you could post some code snippets I bet we could help you out a bit better. thanks |
|
|||
|
Here is my code, thank you ~
These code in a single controller class called TestController PHP Code:
string(3) "123" PHP Code:
do my codes have any mistake |
|
||||
|
Try this
Code:
// Write a variable into registry
public function registryInAction() {
//build your array
$value = array('index' => '123');
//unless your using more than 1 registry just use the default instance
$registry = Zend_Registry::getInstance();
//set your array in the Registry
Zend_Registry::set('test', $value);
//a better test
if($registry->isRegistered('test')) {
echo ' yoyo variable index has been registered!!<br />';
} else {
echo 'dizam sumphin wentz wrongz!';
}
//clear out $value
$value = null;
// get the index from registry
$value = Zend_Registry::get('test');
var_dump($value);
$this->_helper->viewRenderer->setNoRender();
}
Code:
// Try to read the value from registry
public function registryOutAction() {
// get the index from registry
$value = Zend_Registry::get('test');
var_dump( $value );
$this->_helper->viewRenderer->setNoRender();
}
Anyway, use set() and get() to store and retrieve variables, objects, arrays etc in the registry. I didn't actually run the above code but it follows how I deal with the registry through out my app. Granted I did have some trouble with an array (see op) but I was confusing the registry for session data. See if this works and let me know the outcome. |
|
|||
|
I copied your code and tried again ~
the output of the first action: registry-in Code:
yoyo variable index has been registered!!
array(1) { ["index"]=> string(3) "123" }
but the second action: registry-out Code:
Fatal error: Uncaught exception 'Zend_Exception' with message 'No entry is registered for key 'test'' in /opt/lampp/lib/Zend/Registry.php:145 It seems that, the $value can be registry within the action registry-in and get correct inside, but cannot get it back from the action 'registry-out. Do I need to make some configurations let the registry work? Out of topic: ![]() On the other hand, I think that, my code is works when I was new an instance of Zend_Registry and apply Zend_Registry:setInstance. It is because that, there is the only object of Zend_Registry inside the Zend_Registry when singleton was applied. Of cause the previous registered registry will be destroy after setInstance() was called, but the it should be work if I never re-setInstance() , right?? If my concept is not correct please let me know because I am just a newbie in PHP and Zend framework ~ ![]() |
![]() |
| Thread Tools | |
| Display Modes | |
|
|