我正在构建一个CodeIgniter站点,并尝试在控制器中使用php-ABTest。
我将phpabtest.php文件保存为"helpers"文件夹中的phpabtest_helper.php,并将其加载到控制器中。它在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