Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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布局的效率_Php_Performance - Fatal编程技术网

PHP布局的效率

PHP布局的效率,php,performance,Php,Performance,我有一个中心主题类,可以加载我的MVC(L)应用程序的所有不同部分 现在我正在加载其他控制器,如下所示: $data['header'] = $this->theme->controller('content/header'); $data['content_top'] = $this->theme->controller('common/contenttop'); $data['content_top_blocks'

我有一个中心主题类,可以加载我的MVC(L)应用程序的所有不同部分

现在我正在加载其他控制器,如下所示:

$data['header']                 = $this->theme->controller('content/header');
$data['content_top']            = $this->theme->controller('common/contenttop');
$data['content_top_blocks']     = $this->theme->controller('common/contenttopblocks');
$data['column_left']            = $this->theme->controller('common/columnleft');
$data['breadcrumb']             = $this->theme->controller('common/breadcrumb');
$data['column_right']           = $this->theme->controller('common/columnright');
$data['content_bottom_blocks'] = $this->theme->controller('common/contentbottomblocks');
$data['content_bottom']         = $this->theme->controller('common/contentbottom');
$data['footer']                 = $this->theme->controller('content/footer');
我突然想到,由于所有的公共控制器都是被调用的,所以将它们全部移动到我的主题中以消除一些膨胀和冗余可能是有意义的,毕竟OOP不必反复编写相同的代码

所以我试过了,似乎效果不错,看起来是这样的:

$this->theme->public_controllers['header'] = 'content/header';
$this->theme->public_controllers['footer'] = 'content/footer';

foreach ($this->theme->public_controllers as $key => $file):
    $data[$key] = $this->theme->controller($file);  
endforeach;
但这带来了几个问题

如果你算上行数的差异,是9对6。。。所以这并不是真正的去除浮肿。这会改变控制器的渲染顺序

所以我的问题是,第一,既然保存的行数只有3行,那么它值得我花时间吗?它是否让阅读更容易,或者在代码风格方面更正确


而且,将呈现CSS的页眉控制器从堆栈顶部移出会在不同的平台上产生不同的效果吗?还是这一点都不重要?

感谢halfer的建议和评论

我以堆栈顺序解决了这个问题,只需将最常见的页眉和页脚添加到我的主题类中的默认控制器数组中,然后将行数减少到3行。3线对9线的差异足以保证改变它

现在,对于只需要执行默认设置的控制器:

foreach ($this->theme->get_controllers() as $key => $file):
    $data[$key] = $this->theme->controller($file);  
endforeach;
又好又干净

如果我需要更改页眉或页脚,我可以这样做:

$this->theme->set_controller('header', 'shop/header');
如果我想移除一个不需要的控制器:

$this->theme->unset_controller('breadcrumb');

完全值得付出努力,谢谢halfer。

这在代码审查方面可能会更好,但在我看来这两种方法都不好。我想我会稍微同意循环的改变,FWIW。你所说的“不同平台之间的差异”是什么意思?你是说不同的服务器平台吗?这不应该有什么区别,不。我说的不同平台是指浏览器、PHP版本、设备和yes服务器平台。CSS在哪里呈现很重要,但我不知道浏览器会以不同的方式处理。CSS通常最好放在标题中,因为它会在呈现文档之前被读取;如果您将其放在页脚中,并且该页面需要它,则可以在未设置样式和设置样式的呈现之间获得“样式闪烁”。我怀疑浏览器在这方面会有很大的不同。当然,你应该在所有浏览器中测试它,以检查它是否有区别
:-)