CodeIgniter Forums

Full Version: newbie: making variables available?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]Bill the Grue[/eluser]
Hello folks

I'm embarrassed to even ask this, but I am learning, so here goes.

I'm using dx_auth - it's working great. I want to make a variable available, is_logged_in for obvious reasons in my footer.

When I try to simply echo this variable I get an error - Undefined property: CI_Loader::$dx_auth

I suspect I'm not including something somewhere, and I could use some guidance. Can anyone point me in the right direction?

Thank you and warmly,

Bill

El Forum

[eluser]sophistry[/eluser]
post code.

El Forum

[eluser]Bill the Grue[/eluser]
Thanks :-)

Here is the very simple code from the footer.php view file:

Code:
<hr>
<a href="/">Home</a> | <a href="/auth/">Login</a> | <a href="/nations/">Nation Information</a> | <a href="/auth/logout/">Logout</a>
<br />
<br />

&lt;/body&gt;
&lt;/html&gt;

I'm trying to echo a simple variable $is_logged_in(); but it gives the error I mentioned above.

I don't have a footer controller (do I need one?).

Thank you!

Bill

El Forum

[eluser]TheFuzzy0ne[/eluser]
I think there's a global function for this called is_logged_in() that you can use.

El Forum

[eluser]sophistry[/eluser]
yes, post code where the error is happening. the view code is only one part of it.

El Forum

[eluser]Bill the Grue[/eluser]
ah.

I only have a view code for my footer - I don't have anything else, just a view for my footer. What I'm trying to do is grab data from a variable (is_logged_in). I've programmed in php a while ago, and I remember setting variables as global - I just don't know how to do that.

So if I use this view code for my footer:

Code:
<hr>
<a href="/">Home</a> | <a href="/auth/">Login</a> |<a href="/auth/logout/">Logout</a>
<br />
<br />

&lt;?php echo $is_logged_in; ?&gt;

&lt;/body&gt;
&lt;/html&gt;


I get this error:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: is_logged_in

Filename: views/footer.php

Line Number: 6

I think I'm not understanding how variables are inherited. Do I need a footer controller?

El Forum

[eluser]TheFuzzy0ne[/eluser]
Try this:
Code:
<hr>
<a href="/">Home</a> | <a href="/auth/">Login</a> |<a href="/auth/logout/">Logout</a>
<br />
<br />

&lt;?php echo (is_logged_in()) ? 'Logged in' : '<b>Not</b> logged in; ?&gt;

&lt;/body&gt;
&lt;/html&gt;

El Forum

[eluser]TheFuzzy0ne[/eluser]
OK, I'm lost... Where is $is_logged_in defined?

El Forum

[eluser]sophistry[/eluser]
find the controller and post the code that you find there. the view code does not help in this instance because in CI the variables are defined in the controller.

if you don't know what a controller is, please check the handy dandy manual which features prominently on the home page of the codeigniter.com website : (hint - they call it the "User Guide")

El Forum

[eluser]Bill the Grue[/eluser]
I think this might be the essence of my problem - I don't /have/ a controller for my footer - it's just a view file. No controller. Does every view file need a controller?

I've checked out the handy dandy user guide, and I've built other controllers (and I can pass data from them to view files). Do I need a controller for every view?

As I mentioned in my first post, I'm a newbie, and I understand I may have significant confusion about MVC, and how it works. I'll make a controller for my footer, and report back.

I appreciate the hand holding. I really look forward to not being so clueless about this.

Warmly,

Bill
Pages: 1 2