php - 带有 PHPABTest 的 CodeIgniter

标签 php codeigniter ob-start

我正在构建一个 CodeIgniter 站点,并尝试使用 php ABTest在 Controller 中。

我保存了 phpabtest.php file作为“helpers”文件夹中的 phpabtest_helper.php,并将其加载到 Controller 中。它在 PHP 逻辑中初始化如下:

public function view($name)
    {
    $this->load->helper('phpab');
    $testpopup = new phpab('test_popup');
    $testpopup->add_variation("popup");

    $type = $this->Types->getTypeBySlug($name);
    $data['type'] = $type;
    $data['items'] = $this->Items->getItemsByType($type->id);

    $alltypes = $this->Types->getAll();
    $headerdata['alltypes'] = $alltypes;
    $headerdata['current'] = $type->id;
    $this->load->view('header');
    $this->load->view('typeheader', $headerdata);
    if($testpopup->get_user_segment()=='popup'){
            $this->load->view('type_new', $data);
    } else{
        $this->load->view('type', $data);
    }
    $this->load->view('footer');

它在我的本地主机上工作正常,但是当我将它上传到服务器时,它中断了,只显示一个空白页面。我已将问题与 new phpab 对象的初始化隔离开来。在帮助程序中,它执行 ob_start(array($this, 'execute')); 并且这一行似乎是破坏代码的原因。

我应该查看哪些服务器设置才能使其正常工作?我假设这是服务器设置问题,因为它在我的本地主机上运行良好。如果我错了并且是其他问题,我该如何解决?

最佳答案

您可能需要检查您的 PHP 设置。您会在 php.ini 文件中找到一个名为 output_buffer 的设置,该设置可能被设置为 Off。

从 php.ini 执行:

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit.  You can enable output buffering during runtime by calling the output
; buffering functions.  You can also enable output buffering for all files by
; setting this directive to On.  If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
output_buffering = 4096

关于php - 带有 PHPABTest 的 CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17358218/

相关文章:

php - 用于 PHP 托管的 PowerPC Linux 计算机总是抛出 "Balloc() allocation exceeds list boundary"错误

php - 如何使用 PHP 对 MySQL 表中的每一列求和

php - ob_start() 正在部分捕获数据

php - 我的 PHP 代码为呈现的下一个 html 页面运行,而不是为当前页面运行

php - 代码点火器 2 : not loading MY_Loader class

php - 阻止从地址栏访问仪表板部分

php - 如何使用 PHP 和 Codeigniter 处理 foreach 中 mysql 中的 SELECT(MAX())

javascript - 如果选中单选按钮,则在 Codeigniter 中显示 div

PHP ob_start&flush - 在循环中打印和清理文本