How to add condition only logged-in users can view the page in Social Engine

Social engine is based on MVC structure so sometimes user wants only logged-in user can view some pages like 'Create a Blog' page only visible to logged-in user If non logged-in user trying to access that page than user redirect to require user login form.

For achieve this you need to add this following code in any controllers file under specific action:


if( !$this->_helper->requireUser->isValid() ) return;

Example: (Blog Module -> indexcontroller.php)

<?php

class Blog_IndexController extends Core_Controller_Action_Standard
{
  
  public function createAction()
  {
    if( !$this->_helper->requireUser->isValid() ) return;  

According to above example if any non logged-in user trying to access the blogs create page than user redirect to require user login form.

user Authentication


If you have any question or query, feel free to ask using below comments form. Thanks!

Post a Comment

0 Comments