Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6040219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:28:56+00:00 2026-05-23T06:28:56+00:00

Model : <?php class Blogm extends CI_Model{ function __construct() { // Call the Model

  • 0

Model:

<?php 
class Blogm extends CI_Model{

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function get()
    {
        $query = $this->db->get('post', 1);
        return $query->result();
    }
}
?> 

View:

<h2>

<?php 
foreach($query as $a):
echo $a;
endforeach;
?>

</h2>
</body>
</html> 

Controller:

<?php
class Blog extends CI_Controller{

    public function __construct(){
        parent::__construct();
        $this->load->model('Blogm','',TRUE);
    }
    public function index(){

        $data['title'] = 'Sblog';
        $data['message'] = 'My Sblog';
        $data['menu_item'] = array('home','contact');

        $this->load->view('headerv.php', $data);

        $data['query'] = $this->Blogm->get();

        $this->load->view('bodyv.php', $data);
        //$this->load->view('sidebarv.php');
        //$this->load->view('footerv.php');
    }
}

    ?> 

Database:

id    int(11)            No    None    auto_increment                                  
    title    text
MIME: text/plain    latin1_swedish_ci        No    None                                    
    content    text
MIME: text/plain    latin1_swedish_ci        No    None                                    
    time    timestamp        on update CURRENT_TIMESTAMP    No    CURRENT_TIMESTAMP    on update CURRENT_TIMESTAMP                                  
    posted    int(1)            No    0 

Database has only one entry…

This is my error..

A PHP Error was encountered

Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: views/bodyv.php

Line Number: 5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:28:57+00:00Added an answer on May 23, 2026 at 6:28 am

    Even though you are running ->get() with a LIMIT of 1, it still returns a result set.

    What you are actually doing is, looping through your set and printing the single object, which can’t be done unless it has a toString() method. This is why CI is complaining Object of class stdClass could not be converted to string.

    Change your code to

    foreach($query as $obj):
       echo $obj->property; //where property is a column
    endforeach;
    

    http://codeigniter.com/user_guide/database/active_record.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in my Comic Model as such: <?php class Comic extends
i created a model object in PHP class User { public $title; public function
With include('basemodel.php'); I get Fatal error: Class 'BaseModel' not found in C:\xampp\htdocs\allsides\account\model.php on line
I have the following model : class Model extends BaseModel { public function save($conn
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\system\application\models\users_model.php on
I've got a little problem overriding the Magento core class: Core/Rule/Model/Rule.php. I think I'm
I'm not sure if this is a trivial questions but in a PHP class:
this is a General Question about MVC .. I wrote a PHP Class that
I have a Model called blog_model. The code for its constructor is below: class
I got RegisterController.php and inside of it I got: class RegisterController extends AppController {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.