Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter无法调用控制器内的函数_Php_Codeigniter - Fatal编程技术网

Php Codeigniter无法调用控制器内的函数

Php Codeigniter无法调用控制器内的函数,php,codeigniter,Php,Codeigniter,谢谢你的回答 所以我的Codeigniter还有一个问题,它仍然是同一个项目,只是计算数据库中的数据行 我想做的是在控制器中创建一个函数,然后在视图中调用该函数 这是我的原始代码: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Dash_control extends CI_Controller { public function __construct()

谢谢你的回答

所以我的Codeigniter还有一个问题,它仍然是同一个项目,只是计算数据库中的数据行

我想做的是在控制器中创建一个函数,然后在视图中调用该函数

这是我的原始代码:

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

class Dash_control extends CI_Controller {

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



    public function index()
    {
        $data['cashtotal']=$this->dash_model->totalCash();
        $data['approvedtocash']=$this->dash_model->cashapproved();
        $data['rejectedtocash']=$this->dash_model->cashrejected();

        $this->load->view('dashboard',$data);
    }

}
我做错了什么?有什么我遗漏的吗? 所以我不能在控制器内创建多个函数? 谢谢你

更新

我听从了萨蒂的指导,结果成功了。谢谢! 由于这是一个表,我想添加另一个函数,因此我将其添加如下:

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

class Dash_control extends CI_Controller {

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



    public function index()
    {
        $this->CashTransSum();
        $this->PayTransSum();
    }

    public function CashTransSum()
    {
        $data['cashtotal']=$this->dash_model->totalCash();
        $data['approvedcash']=$this->dash_model->cashapproved();
        $data['rejectedcash']=$this->dash_model->cashrejected();

        $this->load->view('dashboard',$data);
    }

    public function PayTransSum()
    {
        $data['paytotal']=$this->dash_model->totalPay();
        $data['approvedpay']=$this->dash_model->payapproved();
        $data['acqrejectedpay']=$this->dash_model->payrejected();

        $this->load->view('dashboard',$data);
    }

}

这里说我需要给它打一次电话。。。哪一个?我把密码搞错了吗

您需要在
索引
函数中调用另一个函数()

 public function index()
    {

        $this->anotherfunction();// call your function
    }
public function anotherfunction()
    {
        $data['cashtotal']=$this->dash_model->totalCash();
        $data['approvedtocash']=$this->dash_model->cashapproved();
        $data['rejectedtocash']=$this->dash_model->cashrejected();

        $this->load->view('dashboard',$data);
    }

您需要在
索引中调用
另一个函数()
,如下所示

 public function index()
    {

        $this->anotherfunction();// call your function
    }
public function anotherfunction()
    {
        $data['cashtotal']=$this->dash_model->totalCash();
        $data['approvedtocash']=$this->dash_model->cashapproved();
        $data['rejectedtocash']=$this->dash_model->cashrejected();

        $this->load->view('dashboard',$data);
    }

您遇到的错误是完全正常的,您需要用所有变量填充
$data
数组,请尝试以下操作:

protected $data;

public function index()
{
    $this->CashTransSum();
    $this->PayTransSum();

    $this->load->view('dashboard', $this->data);
}

public function CashTransSum()
{
    $this->data['cashtotal']=$this->dash_model->totalCash();
    $this->data['approvedcash']=$this->dash_model->cashapproved();
    $this->data['rejectedcash']=$this->dash_model->cashrejected();
}

public function PayTransSum()
{
    $this->data['paytotal']=$this->dash_model->totalPay();
    $this->data['approvedpay']=$this->dash_model->payapproved();
    $this->data['acqrejectedpay']=$this->dash_model->payrejected();
}

您遇到的错误是完全正常的,您需要用所有变量填充
$data
数组,请尝试以下操作:

protected $data;

public function index()
{
    $this->CashTransSum();
    $this->PayTransSum();

    $this->load->view('dashboard', $this->data);
}

public function CashTransSum()
{
    $this->data['cashtotal']=$this->dash_model->totalCash();
    $this->data['approvedcash']=$this->dash_model->cashapproved();
    $this->data['rejectedcash']=$this->dash_model->cashrejected();
}

public function PayTransSum()
{
    $this->data['paytotal']=$this->dash_model->totalPay();
    $this->data['approvedpay']=$this->dash_model->payapproved();
    $this->data['acqrejectedpay']=$this->dash_model->payrejected();
}

你还在上指数吗?如果是,则错误是正确的。如果您仍然想使用index方法,只需在那里包含声明即可。您仍然使用index吗?如果是,则错误是正确的。如果您仍然想使用index方法,只需在其中包含声明即可。
 public function index()
    {

        $this->anotherfunction();// call your function
    }
public function anotherfunction()
    {
        $data['cashtotal']=$this->dash_model->totalCash();
        $data['approvedtocash']=$this->dash_model->cashapproved();
        $data['rejectedtocash']=$this->dash_model->cashrejected();

        $this->load->view('dashboard',$data);
    }
protected $data;

public function index()
{
    $this->CashTransSum();
    $this->PayTransSum();

    $this->load->view('dashboard', $this->data);
}

public function CashTransSum()
{
    $this->data['cashtotal']=$this->dash_model->totalCash();
    $this->data['approvedcash']=$this->dash_model->cashapproved();
    $this->data['rejectedcash']=$this->dash_model->cashrejected();
}

public function PayTransSum()
{
    $this->data['paytotal']=$this->dash_model->totalPay();
    $this->data['approvedpay']=$this->dash_model->payapproved();
    $this->data['acqrejectedpay']=$this->dash_model->payrejected();
}