在 CodeIgniter 中使用自定义帮助程序时出错
在 CI 中创建自定义帮助程序时,我没有得到一些东西......
我有文档,但它似乎并没有真正显示如何格式化帮助程序中的函数。
我应该将代码放在 php 括号内,还是简单地使用函数代码?因为现在,如果我尝试将要使用的函数放在帮助程序文件的 php 括号内,它将显示错误并拒绝加载。
<?php
public function build_Home($page_Name,$rank,$thread,$sector)
{
$data['CSS'] = "css/style_centre_paiement_paiements_1.css";
$data['PAGE_NAME'] = "css/style_centre_paiement_paiements_1.css";
$data['RANK'] = "css/style_centre_paiement_paiements_1.css";
$data['THREAD'] = "css/style_centre_paiement_paiements_1.css";
$data['FULL_NAME'] = "css/style_centre_paiement_paiements_1.css";
$data['SECTOR'] = "css/style_centre_paiement_paiements_1.css";
$this->load->model('Privileges_model');
$rank_ID = $this->Privileges_model->gather_Rank_ID($rank);
$page_ID = $this->Privileges_model->gather_Page_ID($page_Name);
$privilege = $this->Privilege_model->gather_Privileges($page_ID,$rank_ID);
switch ($privilege) {
case "admin":
echo "i égal 0";
break;
case "paren":
echo "i égal 1";
break;
case "anima":
echo "i égal 2";
break;
$data['C1'] = "<li><a class='' href='www.google.ca' ></a></li>";
$data['C2'] = "css/style_centre_paiement_paiements_1.css";
$data['C3'] = "css/style_centre_paiement_paiements_1.css";
$data['C4'] = "css/style_centre_paiement_paiements_1.css";
$data['C5'] = "css/style_centre_paiement_paiements_1.css";
$data['C6'] = "css/style_centre_paiement_paiements_1.css";
$data['C7'] = "css/style_centre_paiement_paiements_1.css";
}
?>
该功能显然尚未完成,所以不要介意。但您应该介意的是,这在文件中不起作用。它显示一个错误。
我应该放一个类头吗?
There is something I don't get in the creation of custom helpers in CI...
I've the docs, but it doesnt seem to really ever show how to format the functions in the helper.
Am I supposed to put the code inside php brackets, or simply use function code ? Because right now, If I try to put the functions I want to use inside the php brackets in the helper file, it will show an error and refuse to load.
<?php
public function build_Home($page_Name,$rank,$thread,$sector)
{
$data['CSS'] = "css/style_centre_paiement_paiements_1.css";
$data['PAGE_NAME'] = "css/style_centre_paiement_paiements_1.css";
$data['RANK'] = "css/style_centre_paiement_paiements_1.css";
$data['THREAD'] = "css/style_centre_paiement_paiements_1.css";
$data['FULL_NAME'] = "css/style_centre_paiement_paiements_1.css";
$data['SECTOR'] = "css/style_centre_paiement_paiements_1.css";
$this->load->model('Privileges_model');
$rank_ID = $this->Privileges_model->gather_Rank_ID($rank);
$page_ID = $this->Privileges_model->gather_Page_ID($page_Name);
$privilege = $this->Privilege_model->gather_Privileges($page_ID,$rank_ID);
switch ($privilege) {
case "admin":
echo "i égal 0";
break;
case "paren":
echo "i égal 1";
break;
case "anima":
echo "i égal 2";
break;
$data['C1'] = "<li><a class='' href='www.google.ca' ></a></li>";
$data['C2'] = "css/style_centre_paiement_paiements_1.css";
$data['C3'] = "css/style_centre_paiement_paiements_1.css";
$data['C4'] = "css/style_centre_paiement_paiements_1.css";
$data['C5'] = "css/style_centre_paiement_paiements_1.css";
$data['C6'] = "css/style_centre_paiement_paiements_1.css";
$data['C7'] = "css/style_centre_paiement_paiements_1.css";
}
?>
The function is obviously not completed so don't mind it. What you should mind, though, is that this doesnt work in the file. It shows an error.
Am I supposed to put a class header ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为是在函数声明中使用关键字
public
导致了错误。由于帮助程序文件包含普通函数列表,因此您不必在其中使用public
。只要忽略它,你的助手就应该可以正常工作。I think it is the use of keyword
public
in function declaration that's giving you the error. Since a helper file contains a list of plain functions, you don't usepublic
there. Just omit it and your helper should work fine.