Difference between #1 and #2 of Custom Archive in Blog system

unchanged
Title
Custom Archive in Blog system
unchanged
Category
Tips
unchanged
Tags
cdbcriteria, archive, blog customization, post, archive in demo blog
changed
Content
Hi I had made simple archive system for blog system that can handle tbl_post. I
had used simple CDbCriteria not more than that. I know there is more and many
better way to this but I think this will give some idea to  users to generate
new idea or customized or modified this version of code.


~~~
[php]
//in module define

	public $year;
	public $month;
~~~

In controller controller of view you can use this. I had used here view for
testing.


~~~
[php]
<?php
$monthsvalue =
array('1'=>'January','2'=>'Feburary','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');


$condition = new CDbCriteria;
$condition->select='YEAR(t.createddate) as year'; //declare year in post
model model
$condition->distinct=true;
$condition->order ='createddate DESC';

$yeardataarticle = Post::model()->findAll($condition);

foreach ($yeardataarticle as $ya):
$year =$ya->year;

echo '<br />';
echo $year;
$monthcriteria = new CDbCriteria;
$monthcriteria->select ='MONTH(t.createddate) as month'; // declare month in
post model
$monthcriteria->condition ='YEAR(t.createddate)=:year';
$monthcriteria->params=array(':year'=>$year);
$months = Post::model()->findAll($monthcriteria);
	foreach ($months as $month):
		
		
			$montth = $month->month;
			echo '<br />';
			
			foreach($monthsvalue as $key=>$value):
			
					if (!isset(${'printed'.$key.$year})) ${'printed'.$key.$year} = false;
			
			//var_dump('printed'.$key.$year);exit;
			
					if($key==$montth and !${'printed'.$key.$year}){
						
				echo
CHtml::link($value,array('//post/archivepost','year'=>$year,'month'=>$montth));
				${'printed'.$key.$year}=true;
				
				$postcount = new CDbCriteria;
				$postcount->addCondition('MONTH(t.createddate)=:month AND
YEAR(t.createddate)=:year');
				$postcount->params = array(':month'=>$montth,':year'=>$year);
				$count = Post::model()->count($postcount);
				echo ' ('.$count.')';
			}
							if($key==$montth){?>
				<?php echo
CHtml::link($value,array('//post/archivepost','year'=>$year,'month'=>$montth))?>
				<?php }?>
			<?php 
			endforeach;
						$postcount = new CDbCriteria;
			$postcount->addCondition('MONTH(t.createddate)=:month AND
YEAR(t.createddate)=:year');
			$postcount->params = array(':month'=>$montth,':year'=>$year);
			$count = Post::model()->count($postcount);
			echo ' ('.$count.')';
	endforeach; 

endforeach;
?>

~~~