BELAJAR YII

Saya bingung dengan YII, saya baca user guidenya juga bingung. :-[ :( :( :( :(

saya mau membuat. sebelum masuk web ada login area kemudian setelah login mengecek di database MySQL jika benar maka masuk jika tidak maka ada pemberitahuan gimana caranya ???? plissss

Kalau ingin login cek di database, agan bisa ganti code di bagian /protected/components/UserIdentity.php

Di bagian method authenticate(), code di situ masih menggunakan array buat simpan username ama password. Jadi agan ganti saja code disitu.

Kalau dalam tahap belajar, biasanya awali dengan membaca tutorial membuat Blog.

Tutorial blog bisa di-download di sini:http://yii.googlecode.com/files/yii-docs-1.1.8.r3324.zip

Baru setelah itu dilanjutkan mempelajari Guide…

thk gan langsung ke TKP :D

masalahnya kalau mo belajar dulu bos ane butuh cepat !!!!!

Kalau harus cepat sepertinya Guide memang lebih cocok. Ane rasa belajar bagaimana pakai CActiveRecord ama relations

Terus gimana Controller, Views itu yang terpenting sebagai awal. Sisanya, baru seiring waktu nanya di forum~

gimana cara dirrect control ke control lain ?

mau ngapain dirrect antara controler y kalau bole tau??

maaf maksutnya redirect ke kontroler lain

kan kalau belum loggin tidak boleh masuk, jadi di alihkan ke halaman lain.

setau saya fungsi2 d dlamnya satu2. biar satu redirect untuk semua fungsi dalam satu controler

kalau mau batasin akses halaman mana aja di accessRulesnya aja…entr dy dirrect sendiry ke halaman lain




public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}



semoga nyambung yang di tanya dan yang saya jawab :P :P

ane coba gan muuuuaaaachhh :-*

ini ditaruh mana

controlnya ?

y di controller…

agan coba d cari topik [ GII ] itu wizard biar mempercepat bikin controller model view edit delete update cuman tinggal klik2 jadi…tinggal di modif2 doang…hehehehe

udah bos

Kayaknya Perlu belajar OOP(object Oriented Programming) dulu di PHP gan… karena kebanyakan Yii-ers baru langsung membaca user Guide dulu, tapi untuk konsep OOP di PHP belum menguasai… oleh karena itu banyak yang kebingungan … setelah konsep OOP paham dengan Mantab, baru kita belajar MVC … Ini sekedar cerita pengalaman Pribadi gan… semoga dapat jadi masukan…!

OK gan thx :lol: :lol: :lol: :lol:

mau tanya dong ,

ane punya controller untuk actionAdmin macem gini :




public function actionAdmin()

	{

                $kategoriberita = new Kategori;

                if(isset($_GET['Kategori']))

			$kategoriberita->attributes=$_GET['Kategori'];

                

//                if(isset($_POST['Kategori']))

//			$kategoriberita->attributes=$_POST['Kategori'];

//                                

//                $targ = array('admin');

//                foreach($kategoriberita->attributes as $k => $v){

//                    $targ['Kategori['.$k.']'] = $v;

//                }

//          

//                if (isset($_POST['Kategori']))

//                {

//                        $this->redirect($targ);

//                        return;

//                } 

                

		$model=new Kategori('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Kategori']))

			$model->attributes=$_GET['Kategori'];


		$this->render('admin',array(

			'model'=>$model,

                        'kategoriberita'=>$kategoriberita,

		));

	}



untuk model ane buat gini :




<?php


/**

 * This is the model class for table "kategori".

 *

 * The followings are the available columns in table 'kategori':

 * @property integer $id

 * @property string $nama

 */

class Kategori extends CActiveRecord

{

        public $kategori="Politik";

	/**

	 * Returns the static model of the specified AR class.

	 * @return Kategori the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'kategori';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('nama', 'required'),

			array('nama', 'length', 'max'=>100),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, nama', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'nama' => 'Kategori',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('nama',$this->nama,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

        

        public static function getKategory(){

                $criteria = new CDbCriteria;

                $criteria->select='nama';

                $kategori = Kategori::model()->findAll($criteria);

                foreach($kategori as $row){

                    $option[$row->nama]=$row->nama;

                }

                

                return $option;

        }        

}



untuk view admin, macem gini :




<?php

$this->breadcrumbs=array(

	'Kategoris'=>array('index'),

	'Manage',

);


$this->menu=array(

	array('label'=>'List Kategori', 'url'=>array('index')),

	array('label'=>'Create Kategori', 'url'=>array('create')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('kategori-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<h1>Manage Kategoris</h1>


<? $form=$this->beginWidget('CActiveForm')?>

<? echo $form->labelEx($kategoriberita,'Pilih Kategori : ')?>

<? echo $form->dropDownList($kategoriberita, 'kategori',  Kategori::getKategory())?>

<? echo CHtml::submitButton('Search',array('admin'))?>

<? $this->endWidget()?>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

	'model'=>$model,

)); ?>

</div><!-- search-form -->


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'kategori-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id',

		'nama',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>




nah, yang ingin tanyakan, ane pingin ngesearch data kategori berdasarkan menu dropdown yang ane pilih , gmana ya gan biar action saat tombol search di klik maka data yang tampil di table bakalan keluarin data sesuai pilihan dropdown ??? makasih ya buat ya mau jawab …

Kalau mau search berdasarkan dropdown dibagian view admin ada fitur advanced search, kamu bisa tambah kan dropdown diadvanced search tersebut caranya ubah file _search pada view. Coba perhatikan coding dibawah, semoga membantu. :)





<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

        'model'=>$model,

)); ?>