Wednesday, April 18, 2012

Make ajax validation true in your captcha in yiiframework

Maybe you want to use your captcha in your yiiframwork to use in ajaxvalidation to be true. By default the setting may use you as ajaxvalidation false. But when you want to make it available to be in ajax validation true a little bit tricky you have to look.
Let's take alook the solution I get when digging the yii forum..

Thanks to the members there.


In the default form page in your yiiframework you should look like this :


<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
 'id'=>'user-form',
 'enableAjaxValidation'=>false,
        'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
 

Set default page in Clistview or CGridview in the last page yiiframework

By default default page of Clistview or Cgridview only set to the front of clistview or in the first page as default page. But when you want to use the last page as your default page to be viewed to user you have to modified the pagination in the data provider. You can use this to show when you are using the clistview or component that has the pagination object like others. Maybe you can use this as default discussion thread.

Let's take a look the code that you should have to write down.

if(Yii::app()->request->isAjaxRequest){
 $dataProvider=new CActiveDataProvider('KomentarThread',array(
   'criteria'=>array(
     'condition'=>'ID_THREAD=:id_thread',
     'params'=>array(':id_thread'=>$model->ID_THREAD)
   )
 ));
 $p=$dataProvider->pagination;
 $p->setItemCount($dataProvider->getTotalItemCount());
 $p->currentPage=$p->pageCount-1;
 $this->renderPartial('/komentarThread/_comments_all',array(
   'all_komentar'=>$dataProvider)
   ,false,true);
 Yii::app()->end();
}

The part of $p variable is to set your currentPage to the last page.

So enjoy your modification of your data provider...

Thursday, April 12, 2012

Make captcha in yii framework

If you want to make captcha in yiiframework you have gone to the right place. I want to teach you about how to make captcha in yiiframework.

You can make captcha in yiiframework easy because yii has featured to make the captchaa easily. So let't take a look how to make the captcha in yiiframework

To make the capctha you have to do :
  • Add the code rules to your controller id. For example UserController. 
  •  public function actions(){
      return array(
        // captcha action renders the CAPTCHA image displayed on the user registration page
        'captcha'=>array(
          'class'=>'CCaptchaAction',
          'backColor'=>0xFFFFFF,
        ),
      );
     }
    

Thursday, April 5, 2012

URL in yii Framework

Maybe sometime you are confuse about the standard getting url in Yii Framework. You can use some of the pattern below of the url in yii framework

FULL URL ==> http://www.example.com:8080/project/index.php?r=post/view&id=123

PROPERTY
hostInfo     http://www.example.com:8080
port                                8080
baseUrl                                 /project
url                                     /project/index.php?r=post/view&id=123
requestUri                              /project/index.php?r=post/view&id=123
scriptUrl                               /project/index.php
queryString                                                r=post/view&id=123
scriptFile                 /var/www/html/project/index.php

You can access this url with the code of url :


Yii::app()->request->hostInfo;
Yii::app()->request->port; 
Yii::app()->request->baseUrl;
Yii::app()->request->url; //and the other property

Now You can choose your property you need

Tuesday, April 3, 2012

Using CJuiAutoComplete in yii framework

In the version 1.1.3 yii CAutoComplete was deprecated, so for better result you should consider using CJuiAutoComplete to make autocomplete in yii framework.

To use this widget is more easy to use but with the multiple selections of CJuiAutoComplete maybe you should have to implements more javascript functions.

Let's take a look how to make CJuiAutoComplete with multiple selection enabled. Assume you have code in the article in views article /protected/views/article/_form.php. And I have table with just only 2 fields : id_tag and name