Restrict access to Single Pages

Permalink
Newbie here. I am designing a site that will require several single-pages as I will be implementing database searches to external datasources, etc.
One thing that I am trying to determine is. How do I go about making certain functions of the single page accessible only to logged in users?

Example.
I would like the public to have access to search, in this case clasified ad's. However in order to respond, a login must be required.

If that is to granular at first. I might just like to block access to the single-pages unless they are registered users.

 
mkly replied on at Permalink Reply
mkly
Typically there are two places you can restrict the functionality.

In your view code you can do
<?php $u = new User(); ?>
<?php if($u->isLoggedIn()): ?>
  <p>Only for the logged in users</p>
<?php endif; ?>


In your controller code you do a similar
$u = new User();
if($u->isLoggedIn()) {
  // do search or whatever
} else {
  // this will run do_login and give them
  // the standard "A username and password are required."
  $this->redirect('/login', 'do_login');
}