-1

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?

Qirel
  • 25,449
  • 7
  • 45
  • 62
VinceGraphic
  • 85
  • 1
  • 9
  • 3
    wow, you didn't even try to search it hah? http://stackoverflow.com/questions/12294527/passing-variable-from-controller-to-view-in-codeigniter – Carlos Fdev Sep 21 '16 at 13:47

3 Answers3

1

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;
?>
Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
1

You can do something like this:

Controller:

public function index() {

    $sample['phone'] = "call: 887-65-31";

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

}

In View:

You can print $phone where you want to print.

Virb
  • 1,639
  • 1
  • 16
  • 25
0

In the controller:

public function index() {

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

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

In the view:

<?php
    echo $sample 
?>
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Melkikun
  • 46
  • 1
  • 7