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

Wednesday, March 14, 2012

How to add multi-language site in yii framework

To make multi language in your yii framework you have to implements some rules. You can use the session variables to make the translation between your page. With the the documentation you can look at here.

I have to implements this to make the translation page. You can follow the instruction in that articles that not almost I discuss in this page.

But when I finish implement that step, I can make my own translation page on the protected/messages/<your language id>/<your category>.php files..

For the example :

../protected/messages/id/translation.php

The example of the translation page that I use like this
<?php
/**
 * Bahasa Indonesia Yang digunakan untuk menerjemahkan
 */
return array(
  //------NAVIGASI MENU------------//
  'Home'=>'Beranda',
  'About'=>'Tentang',
  'Contact'=>'Kontak',
  'Login'=>'Masuk',
  'Logout'=>'Keluar',
  
  
  
  //-----------ISI KONTEN DEPAN------------------//
  'What are You Looking For?'=>'Apa Yang Anda Cari?',
  'Sell Your Products'=>'Mau Menjual Barang',
  'Products'=>'Barang',
  'Services'=>'Jasa'
  
  );
?>

Oke when you finish that I use my native languages (Indonesian=ID) and than I can use that for my translation in my code using this example in your view files.



echo Yii::t('translation','Home');

Tuesday, March 13, 2012

Alternative Way to make Dropdown menu in yii

Maybe you are a newbie and want to make dropdown in yii just like me before. Oke to make dropdown menu in yii is simple. You can use this solution to make your Dropdown list..
Maybe you can check my post before here

From there you can use this in two ways of using dropdown list in yii framework

The first one is just like my post before :

<div class="row">
  <?php echo $form->dropDownList($model,'country_id',
   CHtml::listData(Country::model()->findAll(), 'id', 'country_name'),
   array('empty'=>'Select Country'))?>
 </div>

And the other option is using CHtml::dropDownList like this suppose you have to make your view class with the Users model

<div class="row">
  <?php echo CHtml::dropDownList('Users[country_id'],'',
   CHtml::listData(Country::model()->findAll(), 'id', 'country_name'),
   array('empty'=>'Select Country'))?>
 </div>
That's the other option that you can choose..