Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Message: Object of class stdClass could not be converted to string
#1

[eluser]Roy MJ[/eluser]
I was trying to get once field value from database and error is showing saying cant convert to string.

The controller is as follows :
Code:
function storage($selected_stack=''){
if($selected_stack=='')
{
$selected_stack=$this->input->post('selected_stack');
}
$this->data['selected_stack'] = $selected_stack;
$this->session->set_userdata('storage_id', $selected_stack);
$row = $this->Stack_model->addstacks($selected_stack);
$this->data['stackname'] = $this->Stack_model->getstack($selected_stack);
$this->data['storage_id'] = $this->session->userdata('storage_id');
$this->data['pagetitle'] = 'Stack';
$this->load->view('stack/addtostorage', $this->data);
}

Model is as follows:

Code:
function getstack($selected_stack)
{
$resultstack    =    $this->db->query("SELECT stack FROM stack WHERE id='$selected_stack'");
return $resultstack->row();
}

View

Code:
<?php echo $stackname?>

error:

Code:
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: stack/addtostorage.php
Line Number: 74
#2

[eluser]Roy MJ[/eluser]
When i do this its printing the contents,

Code:
<?php print_r($stackname)?>


result :

stdClass Object ( [stack] => Travel )

But how can i get the Travel alone to be displayed on the screen..??
#3

[eluser]mihaibaboi[/eluser]
[quote author="Roy MJ" date="1302530755"]
But how can i get the Travel alone to be displayed on the screen..??[/quote]

Code:
print_r($stackname->stack);

Or

Code:
print_r($stackname->getStack());

If the object has setter and getter methods.
#4

[eluser]Josh Holloway[/eluser]
In your view you need to do:

Code:
<?php echo $stackname->stack; ?>
#5

[eluser]Roy MJ[/eluser]
Both
Code:
echo $stackname->stack;
and
Code:
print_r($stackname->stack);

worked for me.. thankyou guys.......




Theme © iAndrew 2016 - Forum software by © MyBB