Commit e8d59fb6 by Alexander Makarov

specified proper namespaces

parent 4a9f0eed
...@@ -12,7 +12,7 @@ return array( ...@@ -12,7 +12,7 @@ return array(
'id' => 'change-me', 'id' => 'change-me',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'preload' => array('log'), 'preload' => array('log'),
'controllerNamespace' => 'app\controllers', 'controllerNamespace' => 'backstage\controllers',
'modules' => array( 'modules' => array(
), ),
'components' => array( 'components' => array(
......
<?php <?php
namespace app\controllers; namespace backstage\controllers;
use Yii; use Yii;
use yii\web\Controller; use yii\web\Controller;
......
<?php
namespace app\models;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* @return array the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, subject, body', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha'),
);
}
/**
* @return array customized attribute labels
*/
public function attributeLabels()
{
return array(
'verifyCode' => 'Verification Code',
);
}
/**
* Sends an email to the specified email address using the information collected by this model.
* @param string $email the target email address
* @return boolean whether the model passes validation
*/
public function contact($email)
{
if ($this->validate()) {
$name = '=?UTF-8?B?' . base64_encode($this->name) . '?=';
$subject = '=?UTF-8?B?' . base64_encode($this->subject) . '?=';
$headers = "From: $name <{$this->email}>\r\n" .
"Reply-To: {$this->email}\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";
mail($email, $subject, $this->body, $headers);
return true;
} else {
return false;
}
}
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
/**
* @return array the validation rules.
*/
public function rules()
{
return array(
// username and password are both required
array('username, password', 'required'),
// password is validated by validatePassword()
array('password', 'validatePassword'),
// rememberMe must be a boolean value
array('rememberMe', 'boolean'),
);
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*/
public function validatePassword()
{
$user = User::findByUsername($this->username);
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', 'Incorrect username or password.');
}
}
/**
* Logs in a user using the provided username and password.
* @return boolean whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
$user = User::findByUsername($this->username);
Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
return true;
} else {
return false;
}
}
}
<?php <?php
namespace app\models; namespace common\models;
class User extends \yii\base\Object implements \yii\web\Identity class User extends \yii\base\Object implements \yii\web\Identity
{ {
......
...@@ -12,7 +12,7 @@ return array( ...@@ -12,7 +12,7 @@ return array(
'id' => 'change-me', 'id' => 'change-me',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'preload' => array('log'), 'preload' => array('log'),
'controllerNamespace' => 'app\controllers', 'controllerNamespace' => 'console\controllers',
'modules' => array( 'modules' => array(
), ),
'components' => array( 'components' => array(
......
...@@ -12,7 +12,7 @@ return array( ...@@ -12,7 +12,7 @@ return array(
'id' => 'change-me', 'id' => 'change-me',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'preload' => array('log'), 'preload' => array('log'),
'controllerNamespace' => 'app\controllers', 'controllerNamespace' => 'frontend\controllers',
'modules' => array( 'modules' => array(
), ),
'components' => array( 'components' => array(
......
<?php <?php
namespace app\controllers; namespace frontend\controllers;
use Yii; use Yii;
use yii\web\Controller; use yii\web\Controller;
......
<?php <?php
namespace app\models; namespace frontend\models;
use yii\base\Model; use yii\base\Model;
......
<?php <?php
namespace app\models; namespace frontend\models;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;
......
<?php <?php
namespace app\models; namespace frontend\models;
class User extends \yii\base\Object implements \yii\web\Identity class User extends \yii\base\Object implements \yii\web\Identity
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment