You are on page 1of 4

Ci t v cu hnh yii

1) Start -> My Computer (right click!) -> Advanced Tab -> Environment Variables ->
Click Path in System variables (windows 7 l Path) -> Edit.
2) -Tip bn thm vo nhng ng dn sau: "C:\xampp\php" v "
C:\xampp\htdocs\yii\framework
3)Khi to ng dng mi C:\xampp\htdocs\>softvn/framework/yiic webapp demo
4) to controler bng cmd C:/xampp/htdocs/demo> C:/xampp/htdocs/softvn/framework/yiic
shell
controller message helloWorld
5) Chtml::link h tr to lin kt
<p><?php echo CHtml::link("Hello",array('message/helloWorld')); ?></p>
6) cu hnh ng dng
-/protected/config/main.php
-ket ni csdl
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=db_yii',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
To crud
- // uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123456',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
- http:// tn host/demo/index.php?r=gii
-to model, to crud


To url thn thin
Vo protected/config/main.php b comment urlManager..
$yii=dirname(__FILE__).'/framework/yii.php';


-This->page Title Tiu trang

Cch 1: Dng form bng cch dng widget.
//Khi to widget s dng Ajax cho Form Active
$form=$this->beginWidget('CActiveForm',array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($model,'name')

));
<?php //Kim tra u vo model ng cha ?
echo $form->errorSummary($model);
?>
<div class="row">
<?php //Khi to trng name
echo 'Tn truy cp:';
echo $form->textField($model,'name');
echo $form->error($model,'name');
?>
</div>
Thm Captcha cho form
-Nu cha bt "gd2" th ta vo file php.ini ri sa li dng ny
M PHP:
extension=php_gd2.dll
<?php $this->widget('CCaptcha',array(
'buttonLabel' => 'Ly code mi',
'clickableImage' => true,
'imageOptions' => array('id' => 'captchaimg')
)); ?>
Vit Li form trn bng cch dng 'CHtml':
M PHP:
<div id='form'>
<?php
echo CHtml::beginForm();
?>
<div id='row'>
<?php echo CHtml::activeLabel($model,'name');?>
<br/>
<?php echo CHtml::activeTextField($model,'name')?>
</div>
<div id='row'>
<?php echo CHtml::activeLabel($model,'email');?>
<br/>
<?php echo CHtml::activeTextField($model,'email')?>
</div>
<div id='row'>
<?php echo CHtml::activeLabel($model,'pass');?>
<br/>
<?php echo CHtml::activePasswordField($model,'pass')?>
</div>
<div id='row'>
<?php echo CHtml::activeLabel($model,'repass');?>
<br/>
<?php echo CHtml::activePasswordField($model,'repass')?>
</div>
<div id='row'>
<?php echo CHtml::activeLabel($model,'date');?>
<br/>
<?php echo CHtml::activeTextField($model,'date')?>
</div>
<div id='send'>
<br/>
<?php echo CHtml::submitButton('ng K',array('id'=>'frmReg','name'=>'frmReg'));?>
</div>
<?php
echo CHtml::endForm();
?>
</div>

To hide the index.php from url I did changes in config/main.php as shown below,
urlManager=>array(
urlFormat=>path,
showScriptName=>false,
rules=>array(
<controller:\w+>/<id:\d+>=>'<controller>/view,

<controller:\w+>/<action:\w+>/<id:\d+>=>'<controller>/<action>,

<controller:\w+>/<action:\w+>=>'<controller>/<action>,
),
),
and I created new .htaccess file in the same directory as my index.php file shown as
below,
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

You might also like