Yii Framework Forum: Configuring Sitecontroller - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Configuring Sitecontroller making my webapp default to login instead of home Rate Topic: -----

#1 User is offline   ikotee 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 24-April 13

Posted 27 April 2013 - 09:34 AM

greetings all

I have read the manual apparently am missing some valid details-after hitting my head for so long, i figured perhaps someone out there has a handy solution. My problem simply is getting my application to authenticate users before access to any page including the home page. i followed larry's tutorial and read the documentation so i realise i need to setup a logincontroller and a view /login/index.php. so i copied all the codes from sitecontroller minus references to contact and about to login. added 'defaultController' =>'login'; in config/main but its not working except errors-

i figure i wont need to make so many changes to get my application to start firing from login. heres my code:

<?php

class LoginController extends SiteController
{
public $layout='/layouts/column1';

public function getPageTitle()
{
if($this->action->id==='index')
return 'Web-based pension pay system';
else
return ''.ucfirst($this->action->id).' Pensioner';
}

public function actionIndex()
{
$this->render('index');
}

public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}

/**
* Displays the login page
*/

public function actionLogin()
{
$model=new LoginForm;

// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}

// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
}

/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout(false);
$this->redirect(Yii::app()->createUrl('/login/index'));
}


} and heres my views

<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm */

$this->pageTitle=Yii::app()->name . ' - Login';
$this->breadcrumbs=array(
'Login',
);
?>

<h1>Login</h1>

<p>Please fill out the following form with your login credentials:</p>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
<p class="hint">
Hint: You may login with <kbd>demo</kbd>/<kbd>demo</kbd> or <kbd>admin</kbd>/<kbd>admin</kbd>.
</p>
</div>

<div class="row rememberMe">
<?php echo $form->checkBox($model,'rememberMe'); ?>
<?php echo $form->label($model,'rememberMe'); ?>
<?php echo $form->error($model,'rememberMe'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton('Login'); ?>
</div>

<?php $this->endWidget(); ?>
</div><!-- form -->


and the error
include(SiteController.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Will appreciate some help
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 27 April 2013 - 10:05 AM

/* moved from Feature Requests */
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users