Welcome Guest, Not a member yet? Register   Sign In
Public variable used in views can do or not?
#1

HAPPY NEW YEAR 2015

For User class as :-
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
User extends MY_Controller 
{

 
  public $tableData;

 
  public function index()
 
  {
 
    ...
 
    $this->tableData  $this->table->generate(); 
 
    $this->load->view('user');
 
  }



For User view as:-
PHP Code:
...
<
div class="table-data">
<?
php echo $this->tableData?>
</div>
... 

for above example I have declare $tableData is public variable then in view <?php echo $this->tableData; ?> this is good or not ?
or I should pass data array via load view
Reply
#2

Happy 2015 to you too! Smile

Think of your situation in terms of coupling. If the data for your view can only come from $this->tableData, your view will be tightly coupled to your class. That means your view will rely on your class to supply the data. That could be ok, unless you can imagine a situation where the data could come from a different source. In that case, it would be better to pass the data via an array.
Reply
#3

RobertSF : Thank you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB