Added DB Access + Error page
This commit is contained in:
23
demos/blog/protected/components/Controller.php
Normal file
23
demos/blog/protected/components/Controller.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Controller is the customized base controller class.
|
||||
* All controller classes for this application should extend from this base class.
|
||||
*/
|
||||
class Controller extends CController
|
||||
{
|
||||
/**
|
||||
* @var string the default layout for the controller view. Defaults to 'column1',
|
||||
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
|
||||
*/
|
||||
public $layout='column1';
|
||||
/**
|
||||
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
|
||||
*/
|
||||
public $menu=array();
|
||||
/**
|
||||
* @var array the breadcrumbs of the current page. The value of this property will
|
||||
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
|
||||
* for more details on how to specify this property.
|
||||
*/
|
||||
public $breadcrumbs=array();
|
||||
}
|
||||
19
demos/blog/protected/components/RecentComments.php
Normal file
19
demos/blog/protected/components/RecentComments.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
Yii::import('zii.widgets.CPortlet');
|
||||
|
||||
class RecentComments extends CPortlet
|
||||
{
|
||||
public $title='Recent Comments';
|
||||
public $maxComments=10;
|
||||
|
||||
public function getRecentComments()
|
||||
{
|
||||
return Comment::model()->findRecentComments($this->maxComments);
|
||||
}
|
||||
|
||||
protected function renderContent()
|
||||
{
|
||||
$this->render('recentComments');
|
||||
}
|
||||
}
|
||||
23
demos/blog/protected/components/TagCloud.php
Normal file
23
demos/blog/protected/components/TagCloud.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
Yii::import('zii.widgets.CPortlet');
|
||||
|
||||
class TagCloud extends CPortlet
|
||||
{
|
||||
public $title='Tags';
|
||||
public $maxTags=20;
|
||||
|
||||
protected function renderContent()
|
||||
{
|
||||
$tags=Tag::model()->findTagWeights($this->maxTags);
|
||||
|
||||
foreach($tags as $tag=>$weight)
|
||||
{
|
||||
$link=CHtml::link(CHtml::encode($tag), array('post/index','tag'=>$tag));
|
||||
echo CHtml::tag('span', array(
|
||||
'class'=>'tag',
|
||||
'style'=>"font-size:{$weight}pt",
|
||||
), $link)."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
39
demos/blog/protected/components/UserIdentity.php
Normal file
39
demos/blog/protected/components/UserIdentity.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UserIdentity represents the data needed to identity a user.
|
||||
* It contains the authentication method that checks if the provided
|
||||
* data can identity the user.
|
||||
*/
|
||||
class UserIdentity extends CUserIdentity
|
||||
{
|
||||
private $_id;
|
||||
|
||||
/**
|
||||
* Authenticates a user.
|
||||
* @return boolean whether authentication succeeds.
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$user=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
|
||||
if($user===null)
|
||||
$this->errorCode=self::ERROR_USERNAME_INVALID;
|
||||
else if(!$user->validatePassword($this->password))
|
||||
$this->errorCode=self::ERROR_PASSWORD_INVALID;
|
||||
else
|
||||
{
|
||||
$this->_id=$user->id;
|
||||
$this->username=$user->username;
|
||||
$this->errorCode=self::ERROR_NONE;
|
||||
}
|
||||
return $this->errorCode==self::ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer the ID of the user record
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
}
|
||||
17
demos/blog/protected/components/UserMenu.php
Normal file
17
demos/blog/protected/components/UserMenu.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
Yii::import('zii.widgets.CPortlet');
|
||||
|
||||
class UserMenu extends CPortlet
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->title=CHtml::encode(Yii::app()->user->name);
|
||||
parent::init();
|
||||
}
|
||||
|
||||
protected function renderContent()
|
||||
{
|
||||
$this->render('userMenu');
|
||||
}
|
||||
}
|
||||
7
demos/blog/protected/components/views/recentComments.php
Normal file
7
demos/blog/protected/components/views/recentComments.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<ul>
|
||||
<?php foreach($this->getRecentComments() as $comment): ?>
|
||||
<li><?php echo $comment->authorLink; ?> on
|
||||
<?php echo CHtml::link(CHtml::encode($comment->post->title), $comment->getUrl()); ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
6
demos/blog/protected/components/views/userMenu.php
Normal file
6
demos/blog/protected/components/views/userMenu.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<ul>
|
||||
<li><?php echo CHtml::link('Create New Post',array('post/create')); ?></li>
|
||||
<li><?php echo CHtml::link('Manage Posts',array('post/admin')); ?></li>
|
||||
<li><?php echo CHtml::link('Approve Comments',array('comment/index')) . ' (' . Comment::model()->pendingCommentCount . ')'; ?></li>
|
||||
<li><?php echo CHtml::link('Logout',array('site/logout')); ?></li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user