VinceGraphic VinceGraphic - 2 months ago 6
PHP Question

How do I retrieve the value of parameter from controller to view?

These is what I have, I'm using Codeigniter MVC.

CONTROLLER

public function index() {

$sample = "call: 887-65-31";

$this->load->view('contact_view', $sample);

}


now how do i retrieve it on contact view page?

Answer

Try this:

Controller

<?php

class Example extends CI_Controller {

    public function index() {
       $viewData['sample'] = "call: 887-65-31";
       $this->load->view('contact_view', $viewData);
    }
}

View

then echo in contact_view like below:

<?php 
   echo $sample;
?>