-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
  • 23,315
  • 7
  • 41
  • 57
VinceGraphic
  • 65
  • 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;
?>
Mr. ED
  • 11,442
  • 13
  • 57
  • 123
Pathik Vejani
  • 4,194
  • 8
  • 52
  • 89
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,610
  • 1
  • 14
  • 24
0

In the controller:

public function index() {

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

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

In the view:

<?php
    echo $sample 
?>
Ashish Ahuja
  • 4,913
  • 10
  • 51
  • 65
Melkikun
  • 46
  • 1
  • 7