Welcome Guest, Not a member yet? Register   Sign In
How to hide certain class functions
#1

[eluser]rjani[/eluser]
Hey guys, I'm new to this forum and also CodeIgniter, and I hope you can help me out.
I'm creating a website, and for easier debugging and development, I thought it'd be good to separate the main controller functions, so that I have a function for example, that communicates with the database ( through a model ) and loads the sidebar. And another one for displaying the navigation, and so on...
Then my index function calls them when needed.

My question is, how can I hide these "include" functions?
Because now if I let's say, go to mysite.com/home/displaysidebar, it displays the sidebar alone, and I don't want that.

Thanks in advance!
#2

[eluser]rjani[/eluser]
I'm sorry, feel free remove this thread.
I've just stumbled upon the solution in the user guide under Private functions.
I just have to put a _ before the function name.
Sorry again.
#3

[eluser]Evil Wizard[/eluser]
"Scope" of methods and properties are not just limited to CI, OOP is based in the encapsulation and in the world of CI Controllers the normal rules "Public", "Private" and "Protected" do not work because of how the _remap(0 functions comes into play, The controller checks itself for a method that exists, and because the controller itself is checking, then scope is not an issue. This does limit controllers from being able to use __call(), __set() and __get(). Also by default if no scope keyword prefixes the method/property name then it is considered to be public, and prefixing the "_" to the method name only really works in the controller.
#4

[eluser]rjani[/eluser]
Thanks for the explanation, I didn't really understand why simply a "private" prefix didn't work
#5

[eluser]Dam1an[/eluser]
[quote author="rjani" date="1242245681"]Thanks for the explanation, I didn't really understand why simply a "private" prefix didn't work[/quote]

2 reasons
1) private was only introduced in PHP5, so it wouldn't work while trying to maintain PHP4 compatability
2) As eveil wizard said, the scope of the controller isn't what it seems
#6

[eluser]Evil Wizard[/eluser]
[quote author="Dam1an" date="1242245810"]
2 reasons
1) private was only introduced in PHP5, so it wouldn't work while trying to maintain PHP4 compatability
2) As eveil wizard said, the scope of the controller isn't what it seems[/quote]

the 2nd isn't really a matter of scope as from the viewpoint of the controller the private, protected and public methods of the controller are all accessible and as such look to the controller object as being the same as public.

I'm sure i used scope if not with properties, then definitely methods in PHP 4.x

but hey, wait till you get to the public static methods and properties that you access without instantiating the class object ;o) ooooooOOOOOOOO

oO( ooooo libraries )
#7

[eluser]tonanbarbarian[/eluser]
as indicated above if you name your functions with a _ at the beginning will not be able to be run
so if you change the function displaysidebar to _displaysidebar it will not be able to be run from the web but can still be accessed inside the controller




Theme © iAndrew 2016 - Forum software by © MyBB