Search code examples
phpcodeigniterredbean

object in Codeigniter


I began use RedbeanPHP and Codeigniter. In Codeigniter manual written, that if you transmit object from controller to view - properties of object become arrays. I try get array ( object of redbeanphp ) in view from controller. For example :

class Welcome extends CI_Controller {

    public function index()     {
        $this->load->library('rb');

        $post = R::dispense('post');
        $post->title = 'HI';
        $post->text = 'Hello World';
        $post->count = 5;

        $this->load->view('welcome_message',$post);
    }
}  

I don't understand, how I must appeal to variable of array ?

<p><?php echo $????['title'] ;?></p>

Solution

  • You could pass the variables for the templates as an array.

    $this->load->view('welcome_message', array('something' => $post));
    

    Then you can access it as $something in your template