Welcome Guest, Not a member yet? Register   Sign In
A few questions about getting started
#1

[eluser]Sayian[/eluser]
Im new to CI, Im also new to OOP.

I have read the manual here on CI, as well as some OOP tutorials ect.

I Have CI Installed and Understand the Concept of what its for.

Here are my questions:

1. In the controller functions, if I placed a variable in lets say the index function, can that variable be accessed outside of that function? Like in another function?

2. In my view files I need to display different HTML depending on if the user is logged in or not, how would this be possible? Isnt it bad practice to use php syntax to check for things in view files?

3. I'd like to set some global variables and have them included in my controller's everytime they load, and if so, would these variables be available to my functions in the controller file?

I guess coming from a procedural way of coding it is difficult for me to understand the scope of where variables stop and where they can be used / not used.

Thanks for the help.
#2

[eluser]Michael Wales[/eluser]
Quote:1. In the controller functions, if I placed a variable in lets say the index function, can that variable be accessed outside of that function? Like in another function?
No - that variable is only accessible within that function. Additionally, it is only available within that particular instance of the class (read: on that page load). To persist data across multiple pages you would need to use other methods (forms, session, cookies, etc).

Quote:2. In my view files I need to display different HTML depending on if the user is logged in or not, how would this be possible? Isnt it bad practice to use php syntax to check for things in view files?
There are numerous ways to achieve this. Personally, I think a fair amount of conditionals is appropriate within the view but if you don't - you could always just load a different view from your Controller depending on the login state.

Quote:3. I’d like to set some global variables and have them included in my controller’s everytime they load, and if so, would these variables be available to my functions in the controller file?
Globals are just that - global. But, be careful - do you really need them to be global? What exactly are you trying to accomplish with them? Remember - PHP is a stateless language, meaning by default there is no transition of data from one request to another. You will need to use cookies, sessions, forms to pass information.




Theme © iAndrew 2016 - Forum software by © MyBB