似乎get_instance()
在Codeigniter 4中不再起作用。但是我需要从BaseController到我的custom_helper中获得一些价值。这是我的代码段:
BaseController.php
<?php namespace App\Controllers;
class BaseController extends Controller
{
protected $helpers = ['custom'];
public function initController(...) {
parent::initController(...);
$myconfig = config('MyConfig');
$this->languages = $myconfig->languages;
$this->selected_lang = $myconfig->site_lang;
$lang_segment = $this->request->uri->getSegment(1);
foreach ($this->languages as $lang) {
if ($lang_segment == $lang->short_form) {
$this->selected_lang = $lang;
$this->lang_base_url = base_url() . $lang->short_form . "/";
}
}
}
}
// Here I need to pass ($this->selected_lang) value to my custom_helper.
custom_helper.php
<?php
if (!function_exists('trans')) {
function trans($string)
{
$language_translations = get_translation_array($this->selected_lang->id);
// --> Here I want to get ($this->selected_lang->id) value from BaseController.
if (!empty($language_translations[$string])) {
return $language_translations[$string];
}
return "";
}
}
function get_translation_array($land_id)
{
.......
}
我不确定是否可以!我是CI4的新手。请提出是否有解决方案。预先感谢。
答案 0 :(得分:0)
您应该在帮助程序中执行所有操作,而不是调用BaseController
FBO = glGenFramebuffers(1)
DBO = glGenRenderbuffers(1)
glBindRenderbuffer(GL_RENDERBUFFER, DBO)
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1280, 720)
glBindFramebuffer(GL_FRAMEBUFFER, FBO)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DBO)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
尽管我不知道您要做什么,但我希望这能对您有所帮助