Alexandre Bolduc
Alexandre Bolduc

Reputation: 825

Error using Custom Helpers in CodeIgniter

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 ?

Upvotes: 0

Views: 290

Answers (1)

Vikk
Vikk

Reputation: 3363

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 use public there. Just omit it and your helper should work fine.

Upvotes: 1

Related Questions