1

I am trying to use 1 model for many controller and views as the model has everything in common except for 4 variables , so as to do this i tried to initialize the variables in the model using a var_setter() function in model and calling it after the model is loaded in the controller but it shows the following error:

enter image description here

and the snippets of the model and controller as given below and also the view is working fine : MODEL:

 class Person_model extends CI_Model {
     var $table ='';
     var $column_order = array();
     var $column_search  = array();
     var $order  = array();

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function var_setter($table,$column_order,$column_search,$order){
        $this->$table = $table;
        $this->$column_order = $column_order;
        $this->$column_search = $column_search;
        $this->$order = $order;
      }
?>

CONTROLLER:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Person extends CI_Controller {

    var $table = 'persons';
    var $column_order = array('date_for_contract','contract_contract_no','contract_company_name' ,'contract_created_by','contract_payment_base','contract_billing_cycle','contract_payment_as_per','contract_pay_mode','contract_credit_limit','contract_stax_paid_by','contract_agreed_payment_days',' contract_loading' ,'contract_unloading','contract_reporting_time','contract_packing_mode','contract_location','contract_diesel_rate_on_contract_day','contract_diesel_rate_variation_by_rate','contract_diesel_rate_variation_by_percentage','contract_start_date','contract_end_date','business_relation_start','risk_name','risk_amount','insurance_cover','contract_remark','contract_from','contract_destination','contract_transit_time','contract_mode','load_limit_from','load_limit_to','contract_rate',null); //set column field database for datatable orderable
    var $column_search = array('date_for_contract','contract_contract_no','contract_from','contract_destination','contract_mode'); //set column field database for datatable searchable just firstname , lastname , address are searchable
    var $order = array('id' => 'desc'); // default order 

    public function __construct()
    {
        parent::__construct();
        $this->load->model('person_model','person');
        $this->person->var_setter($this->$table, $this->$column_order, $this->$column_search, $this->$order);

    }
    public function index()
    {
        $this->load->view('person_view');
    }
?>
7
  • Can you point what line is line 23? Commented Oct 19, 2016 at 9:45
  • $this->person->var_setter($this->$table, $this->$column_order, $this->$column_search, $this->$order); Commented Oct 19, 2016 at 9:48
  • 1
    your $this->$table should be like $this->table Commented Oct 19, 2016 at 9:48
  • still the same error @Nikhil Commented Oct 19, 2016 at 9:51
  • remove the $ after $this. e.g. $this->order Commented Oct 19, 2016 at 9:54

1 Answer 1

1

Change Person_model's var_setter like this

public function var_setter($table,$column_order,$column_search,$order){
    $this->table = $table;
    $this->column_order = $column_order;
    $this->column_search = $column_search;
    $this->order = $order;
  }

and then in Person controller's construct method

$this->person->var_setter($this->table, $this->column_order, $this->column_search, $this->order);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.