php - 使用另一个类的方法,给出错误
问题描述
我正在尝试使用另一个类的方法。这个问题已经被问过好几次了,但在我的情况下,我得到了一个错误。我确定这与我犯的一个错误有关。
class Reports_images extends Reports{
public function testOG(){
return('hi there');
}
}
在另一个文件 Reports.php 中:
require APPPATH.'/controllers/Reports_images.php';
public function appAddPics_post() {
$bakerboyTest = new Reports_images();
$bakerboy = $bakerboyTest->testOG();
$this->response($bakerboy ,REST_Controller::HTTP_OK);
}
我将 CodeIgniter 与休息控制器一起使用,除此之外一切正常。我试图从另一个控制器中的方法返回一个值。
解决方案
那永远行不通。Reports_Images 类扩展了 Reports 类,同时调用了 Reports 类的 testOG 函数。
这将起作用。报告_images.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Reports_images extends CI_Controller{
public function testOG(){
return('hi there');
}
}
然后在 Reports.php 的其他类 Reports 中执行以下操作:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/controllers/Reports_images.php';
class Reports extends Reports_images{
public function appAddPics_post() {
$this->response($this->testOG(), REST_Controller::HTTP_OK);
}
}
推荐阅读
- python - 计算上半场和下半场有多少人加入
- .htaccess - Htaccess 并重定向文件夹的所有内容,但排除主文件夹
- python - 使用 Azure API 在 Azure Boards 上创建新任务
- google-bigquery - 数据融合不允许来自 Bigquery 的 Struct 类型
- kubernetes - microk8s kubeflow仪表板访问-无法与令牌交换授权码:oauth2:无法获取令牌:401未经授权
- c# - 使用 openId connect 如何向请求 c# 添加声明
- stata - 结合两个变量,一个缺失,另一个不缺失
- html - 启用沙盒时 iframe 的来源而不允许相同的来源
- netlogo - 如何在 netlogo 中对矩阵求和
- logging - Datadog:使用 Facet 作为通知目的地