Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Configuring Sitecontroller

$
0
0
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>&lt!-- 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

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>