I have written my cake app to log in registered users and it works
great on view pages where there is a db model associated with a User.
However, on my main pages that aren't necessarily accessing some model
(the PagesController where pages are things like upcoming events,
contact us, about, etc), AuthComponent is not available, or at the
least, the array returns empty---so i cannot retrieve, say, the
username of the person logged in.


I tried creating a model called Page that belongsTo User but that
didn't fix my problem.

To explain a little further, my app shows lists of certain lodgings,
nightclubs, restaurants and things to do for a given city, all of
which is shown whether a user is logged in or not.  I don't understand
where I am going wrong and why.

Here is my AppController:

    <?php
    class AppController extends Controller {
     public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action'
=> 'view'),
            'logoutRedirect' => array('controller' => 'pages',
'action' => 'index')
        )
    );


    function beforeFilter() {
        $this->Auth->allow('login', 'logout','index', 'view',
'condos', 'houses', 'hotels_and_motels', 'print_all_coupons',
'print_coupon', 'search', 'golf', 'charters', 'events', 'nightlife',
'shopping', 'visitors_info', 'contact_us');

    }
    }
    ?>


here is where I access my username in my default page layout:

    <?php if(AuthComponent::user('id')) {
                        echo '<span style="font-variant:small-caps">Hello,
'.AuthComponent::user('username').'</span> | ';
    ?>

Since first posting this on another forum, I have moved all of my
PagesController pages to a folder and controller called Docs.  I have
tried setting $components and $helpers in the AppController for
Session.  I have found that if I echo pr($_SESSION) on my page layout,
on the Docs pages where I have a model call, I get an empty array.  On
my generic pages like the index and contact us, I get an "undefined
variable _SESSION" error.  I am fairly certain I am using a stable
release of cake (grabbed it in November, so it is 2.0.x).  Considering
that I am a noob, I am at a complete and utter loss as to what may be
happening.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to