[英]how to add a custom php function to all opencart pages by default
I need to place a form on every page in an OpenCart system. 我需要在OpenCart系统的每个页面上放置一个表单。 Is it possible that I can include a PHP function somwhere so that it shows on every page?
是否可以在某处包含一个PHP函数,以便在每个页面上都显示它?
Something like: 就像是:
<?php
require_once('../function.php');
test(1);
?>
I just need to know which .tpl
or .php
file to put it in. 我只需要知道将哪个
.tpl
或.php
文件放入即可。
What i did is in 我所做的是在
/system/startup.php
/system/startup.php
require_once(' http://domain.com/orderform/test123.php/ ');
require_once(' http://domain.com/orderform/test123.php/ ');
file test123.php structure as 文件test123.php结构为
<?php
require_once('../function.php');
test(1);
?>
Its working fine , but i am seeing a line on the top of the site saying this 它的工作正常,但我在网站顶部看到一行这样
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at http://domain.com/orderform/test123.php/:42 ) in /home/domain/public_html/system/library/session.php on line 12
警告:session_start():无法发送会话缓存限制器-在/ home / domain / public_html / system / library / session中已发送的标头(输出从http://domain.com/orderform/test123.php/:42开始)。第12行的php
I Think(not tested) u need this ... 我认为(未经测试)您需要这个...
You can add function in header.php So header will be available on all pages and you can use your function on all pages 您可以在header.php中添加函数,因此标头将在所有页面上可用,并且您可以在所有页面上使用函数
myfunciton(){echo "hello";}
opencart22\catalog\controller\common\header.php
In system/helper
you can create your own file eg other.php
在
system/helper
您可以创建自己的文件,例如other.php
// system/helper/other.php
function smpleFunction() {
echo "Hi this works..!";
}
Now you need to include, add the following line 现在您需要包括,添加以下行
// system/startup.php
require_once(DIR_SYSTEM . 'helper/other.php');
Now you can directly call the smpleFunction()
any where you want. 现在,您可以在任意位置直接调用
smpleFunction()
。
Create a file name static.php
in /catalog/controller/information/
在
/catalog/controller/information/
创建文件名static.php
// /catalog/controller/information/static.php
function newfunction() {
echo "I am new !!";
}
Now need to add that file on system/startup.php
by following 现在需要按照以下步骤在
system/startup.php
上添加该文件
// //system/startup.php
require_once(DIR_SYSTEM . '/catalog/controller/information/static.php');
Now you can directly call the newfunction()
any where you want. 现在,您可以在任意位置直接调用
newfunction()
。
In system/library you can create your own functions file eg functions.php 在系统/库中,您可以创建自己的函数文件,例如functions.php
//system/library/functions.php
function testfuntion(){
echo "This is test function";
}
add the following code on index.php to load library functions.php 在index.php上添加以下代码以加载库functions.php
// Cart
$registry->set('cart', new Cart($registry));
// your library functions
$registry->set('functions', new Functions($registry));
now you can use anywhere this function by following code. 现在,您可以通过以下代码在任何地方使用此功能。
$this->functions->testfuntion();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.