Good day.
Can you please tell us how to use your function in CodeIgniter in the template itself? I understand that this is not beautiful and not correct, but otherwise you will have to disassemble an array of this type:

category1
---- category 2
----- category 3
------ category4
------- category 5

And then again to collect in the same form, but with the addition of additional. key to each array. Tried to register $this->myfunct($id) did not work.

    3 answers 3

    Complete nonsense, why in the template to use part of the model?

    Better make a normal model that will process the data for you in the right direction and then render into a template or if you have 2 different outputs, then into different templates.

    Why write part of the data in the output ???

    • It was necessary to do a little differently a hard but practical way, initially pulled out of the second base all the content entered the necessary data into a separate array and then, in the menu building cycle, used another cycle in which the necessary content is being sampled. Initially I wanted to put all the data in the array, but because the array of super duper multidimensional in the morning there were not enough brains to figure out how to process it. - Zeloras

    And where does the model, you mean the controller?

    2Jokerofgod Try it like this, never used the function in mappings, but it should help:

     function myFunction() { $CI = &get_instance(); //тут тело функции } 

    And if you need a normal function that does not use CI methods, then there shouldn't be any problems at all, use it as in a regular php script, having previously framed it in php tags, but as it has already been written here, the use of any kind of php inserts and actions in displaying it is a bad tone!

    • one
      >> inserts and actions in display is a bad tone! I completely agree, but it was only after an hour and a half that it dawned on me how this could be avoided, even though the method turned out to be hard. Thanks for the answer! - Zeloras

    Create your own helper.

    • Thanks, I did it in the following versions, or just ran the array using foreach with a key and, as it were, overwritten the array again. - Zeloras