refiking Posted January 6, 2012 Share Posted January 6, 2012 Ok. So, I'm trying to retrieve the id value from an object. Here is the code I have that works so far: $object = 'object'; $koid = $this->$object; echo '<pre>'; print_r($koid); echo '</pre>'; and this is what is returns: Order Object ( [id:protected] => 5 [stand_by:protected] => test [problem:protected] => test ) what do I need to do to make $koid equal the id value (5 in this case)? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 Well, the code you provided isn't going to output that. So, assuming the object looks like this: $object = (object) array('id' => 5, 'stand_by' => 'test', 'problem' => 'test'); Then you would get "id" by doing $koid = $object->id; Quote Link to comment Share on other sites More sharing options...
refiking Posted January 6, 2012 Author Share Posted January 6, 2012 That didn't work. I also tried this and it didn't work either: $koid = $this->object['id']; echo '<pre>'; print_r($koid); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 $this is only usable in classes. And you are trying to access the object as if it were an array, which it isn't. Quote Link to comment Share on other sites More sharing options...
refiking Posted January 6, 2012 Author Share Posted January 6, 2012 Ok, so what do I need to do to retrieve the id? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 I already showed you how to retrieve a value from an object. Post your actual code. Quote Link to comment Share on other sites More sharing options...
refiking Posted January 6, 2012 Author Share Posted January 6, 2012 What are you talking about? That is my actual code... Same variables and same results exactly. I don't set the id. I am just trying to retrieve it, so I don't create the object. Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 6, 2012 Share Posted January 6, 2012 Post more than 3 lines so I can see what is going on. Quote Link to comment Share on other sites More sharing options...
refiking Posted January 6, 2012 Author Share Posted January 6, 2012 ohhhh..sorry <? class OrderForm extends BaseOrderForm { static protected $choices = array(1 => 'OPEN',2 => 'CLOSED'); static public function getStatusChoices() { return self::$choices; } public function configure() { $years = range(2009, 2012); //Creates array of years between 2009-2012 $years_list = array_combine($years, $years); //Creates new array where key and value are both values from $years list $koid = $this->object; echo '<pre>'; print_r($koid); echo '</pre>'; $this->setWidgets(array( 'id' => new sfWidgetFormInputHidden(), 'stand_by' => new sfWidgetFormInput(array('label' => ' Stand By')), 'problem' => new sfWidgetFormInput(array('label' => ' Problem')), )); $this->setValidators(array( 'id' => new sfValidatorPropelChoice(array('model' => 'Order', 'column' => 'id', 'required' => false)), 'stand_by' => new sfValidatorString(array('max_length' => 5, 'required' => false)), 'problem' => new sfValidatorString(array('max_length' => 50, 'required' => false)), )); } } Quote Link to comment Share on other sites More sharing options...
refiking Posted January 7, 2012 Author Share Posted January 7, 2012 bump...any takers? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 7, 2012 Share Posted January 7, 2012 I still don't know what you are trying to do with $this->object. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted January 7, 2012 Share Posted January 7, 2012 The member is protected, use a public accessor public function getID() { return $this->id; } // edit //instantiate object $object = new className(); echo $object->getID(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.