Yii Framework Forum: How to add "Postdate" widget to the blog demo - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to add "Postdate" widget to the blog demo Rate Topic: -----

#1 User is offline   mocapapa 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 428
  • Joined: 04-January 09
  • Location:Tokyo, JAPAN

Posted 17 February 2009 - 09:05 PM

This is a tiny extension of the well known "blog demo". The purpose of this portlet is to display the posted date in the title line at the head of the post as following picture shows.

Posted Image

* Copy and paste this php script as `blog/protected/components/PostDate.php`.
~~~
[php]
<?php
class PostDate extends Portlet {
  public $cssClass='postdate';
  public $ct;

  protected function renderContent()
  {
    echo "<center><font size=\"3\">\n";
    print $this->ct;
    echo "</font></center>\n";
  }
}
~~~

* Add following css at the end of `blog/css/main.css` or some other appropliate place.
~~~
.postdate
{
      -moz-border-radius:7px;
      font-size:13pt;
      margin: 0;
      padding: 3px;
      margin-bottom:15px;
      background-color:#EEE;
}
~~~

* Modify the source code of the blog demo(`blog/protected/views/post/_post.php`) as follows.
~~~
[php]
<div class="title">
-  <?php echo CHtml::link(CHtml::encode($post->title),array('post/show','id'=>$post->id)); ?>
+     <table><tr><td>
+       <?php $this->widget('PostDate', array('ct'=>date('F<\b\r>j', $post->createTime))); ?>
+     </td>
+     <td>&nbsp;<?php echo CHtml::link(CHtml::encode($post->title),array('post/show','id'=>$post->id)); ?></td>
+     </tr></table>
  </div>
~~~

Have fun ;)


[Updated: Feb 22, 2009]
Collection of the enhancements:
http://code.google.c...gdemo-enhanced/

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users