Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-10-2007, 03:03 AM
Junior Member
 
Join Date: Feb 2007
Posts: 26
Default Difficulties in modifying registering object

Hi,
I created a class "Page" , save it in the lib folder.
<?php
class Page{
var $name = null;
}


I load it into my bootstrap file-index.php, then create an object
$myPage = new Page();
$myPage->name = "BOOTSTRAP";


then I registered it:
Zend::register('myPage',$myPage);

In my indexAction controller, I access the object:
function indexAction(){
$myPage = Zend::registry('myPage');
$myPage->name = "INDEX ACTION";
echo $myPage->name;
}


and in my listAction controller, I access the same object:
function listAction(){
$myPage = Zend::registry('myPage');
echo $myPage->name;
}


Now, when I run the page, First page I got message "INDEX ACTION", good.
But, when I open Index/List , I got message "BOOTSTRAP"... I was expecting to get a message "INDEX ACTION"..
So, it seems that when I execute Index/List, myPage object is re-created again in the bootstrap file, so the value back to the first.
My question is, how can I make myPage not be re-created when I execute Index/List ?
Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-10-2007, 07:14 PM
Junior Member
 
Join Date: Feb 2007
Location: United States
Posts: 7
Default

with the registry, the object is copied, not passed by reference if I remember. This is to prevent the application from modifying the object and causing problems. The zend registry does not allow you to modify a registered object, but I think in the new release this 'feature' has been removed. So you would have to reregister the object.

I wouldnt quote myself on this as I have not used the registry much as I try to avoid it because using getInvokeArg() seems to be a better option when using the zend frontcontroller
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2007, 01:51 AM
Junior Member
 
Join Date: Feb 2007
Posts: 26
Default

thanks a lot!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:07 PM.