Question

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>
Was it helpful?

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

OTHER TIPS

title is your key- so it itself becomes a variable in the view. just use it like a normal variable-

<p><?php echo $title ;?></p>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top