Configuramos en la carpeta config main.php
la ruta de nuestra extension:
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
//Agregamos en el modulo gii para generar cruds con bootstrap
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'pass',
'generatorPaths'=>array(
'bootstrap.gii',
),
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
// application components
'components'=>array(
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
Yii Framework
viernes, 5 de julio de 2013
Autenticación con pass md5 en yii
Despues de generar el medelo de la tabla usuario
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = Usuario::model()->findByAttributes(array('login'=>$this->username));
if ($user === null) {
// No user found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if ($user->password !==md5($this->password)) {
// Invalid password!
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else { // Okay!
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
}
Función del sitecontrolador que manda llamar la vista login.php
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
/* if(Yii::app()->user->isGuest){
$this->layout='//layouts/login';
$this->render('index');
} else {
//$this->layout='/layouts/login';
$this->render('index');*/
$this->layout='//layouts/login';
$model=new LoginForm;
$this->layout='/layouts/login';
// 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(array('/aspirantes/index'));
}
// display the login form
$this->render('login',array('model'=>$model));
}
Si la validación es correcta manda llamar al controlador aspirantes/index
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate()
{
$user = Usuario::model()->findByAttributes(array('login'=>$this->username));
if ($user === null) {
// No user found!
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if ($user->password !==md5($this->password)) {
// Invalid password!
$this->errorCode=self::ERROR_PASSWORD_INVALID;
} else { // Okay!
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
}
Función del sitecontrolador que manda llamar la vista login.php
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
/* if(Yii::app()->user->isGuest){
$this->layout='//layouts/login';
$this->render('index');
} else {
//$this->layout='/layouts/login';
$this->render('index');*/
$this->layout='//layouts/login';
$model=new LoginForm;
$this->layout='/layouts/login';
// 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(array('/aspirantes/index'));
}
// display the login form
$this->render('login',array('model'=>$model));
}
Si la validación es correcta manda llamar al controlador aspirantes/index
miércoles, 19 de junio de 2013
Acceso a variables creadas por nosotros
Dentro de protected En el archivo main.php de la carpeta config
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
'perfil'=>'administrador',
),
aqui se crean y para accesar a ellas es por medio de:
<?php echo Yii::app()->params['adminEmail']; ?>
Nombre de la aplicación y acceso a variables globales
Dentro de protected En el archivo main.php de la carpeta config
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Mi primer proyecto',
'language'=>'es',
'sourceLanguage'=>'en',
'charset'=>'utf-8',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
*/
),
Y para acceder a esas variables desde la vista es por medio de :
<?php echo Yii::app()->name; ?>
<?php echo Yii::app()->languaje; ?>
<?php echo Yii::app()->charset; ?>
URLs limpias en yii
Paso 1: cambiar en el apache la linea AllowOverride none
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
Paso 2. Activamos mod rewrite de apache
$ sudo a2enmod rewrite
Paso 3. En el .htacces que esta en la carpeta portected de nuestro proyecto cambias de deny all a :
Options +FollowSymLinks
IndexIgnore *.*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Paso 4. En el archivo main.php de la capeta config de nuestro proyecto descomentamos las siguientes lineas.
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>'false',
'urlSuffix'=>'.jsp',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
martes, 18 de junio de 2013
Instalar yii en linux
Descargamos el yii de la pagina http://www.yiiframework.com/
la descargamos en opt y generamos un aplicacion con:
cms@desarrollo:/var/www/yii/framework$ ./yiic webapp /var/www/miaplicacion1
la descargamos en opt y generamos un aplicacion con:
cms@desarrollo:/var/www/yii/framework$ ./yiic webapp /var/www/miaplicacion1
Suscribirse a:
Entradas (Atom)