0

I am trying to load controller but neither its giving error or showing blank after loading this controller                                        

$this->load->library('../controllers/invoiceajax');
$this->invoiceajax->sendsecurityinvoice($this->input->post('depositid'),$insert_id,$this->security->xss_clean($this->input->post('securitycheck')));
Mohan Singh
  • 1,142
  • 3
  • 15
  • 30
j sharma
  • 669
  • 1
  • 5
  • 7
  • you should re-use model in controller not controller from controller. – Devsi Odedra Nov 14 '19 at 07:51
  • How can i call a function which is in another controller.I have read out that function can be called by loading another controller. – j sharma Nov 14 '19 at 07:56
  • you should post your controller code - because if you try to share some logic from one of your controller / functions - you probably should relocate that logic. – Atural Nov 14 '19 at 08:31
  • please elaborate, why you want to load controller within another controller ? – 5eeker Nov 14 '19 at 09:09
  • Because I want to use that controller function – j sharma Nov 14 '19 at 09:37
  • or this one? https://stackoverflow.com/questions/32943717/how-to-call-a-controller-from-another-controller-in-codeigniter – Vickel Nov 14 '19 at 16:59
  • or this one: https://stackoverflow.com/questions/6500022/codeigniter-calling-a-method-of-one-controller-from-other – Vickel Nov 14 '19 at 17:00

2 Answers2

0

I think it's not good practice to call another controller's function.

Just try to make it as CodeIgniter's custom helper function and use it in both controller.

Make invoice helper function in application/helpers directory of CI.

$this->load->helper('invoice');

$this->invoice->sendsecurityinvoice($this->input->post('depositid'),$insert_id,$this->security->xss_clean($this->input->post('securitycheck')));
Rise
  • 1,493
  • 9
  • 17
0

You can extend one controller like this and then use this controller in other. It's good practice to save this controller in libraries, not in controllers. This is base controller Base_CI.php in application/libraries

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

class Base_CI extends CI_Controller{
    public function sendsecurityinvoice($data){
      if(!empty($data)){
         return $data;
      }
    }
}

Then in other controller Invoiceajax.php do this:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/Invoiceajax.php';

class Invoiceajax extends Base_CI{
    public function test() {
       return $this->sendsecurityinvoice('Hi');
    }
    var_dump($this->test());
}
stefo91
  • 618
  • 6
  • 16