Hi,
I’m just using the yii blog tutorial and have some strange problems.
I’m now on side 19 and have done what the tutorial said.
PHP have some problems:
http://localhost/blog/index.php?r=post/create
PHP Error
Description
require(content.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory
Source File
E:\Workspace\yii\framework\YiiBase.php(231)
00219:
00220: if(class_exists($alias,false) || interface_exists($alias,false))
00221: return self::$_imports[$alias]=$alias;
00222:
00223: if(isset(self::$_coreClasses[$alias]) || ($pos=strrpos($alias,'.'))===false) // a simple class name
00224: {
00225: self::$_imports[$alias]=$alias;
00226: if($forceInclude)
00227: {
00228: if(isset(self::$_coreClasses[$alias])) // a core class
00229: require(YII_PATH.self::$_coreClasses[$alias]);
00230: else
00231: require($alias.'.php');
00232: }
00233: return $alias;
00234: }
00235:
00236: if(($className=(string)substr($alias,$pos+1))!=='*' && (class_exists($className,false) || interface_exists($className,false)))
00237: return self::$_imports[$alias]=$className;
00238:
00239: if(($path=self::getPathOfAlias($alias))!==false)
00240: {
00241: if($className!=='*')
00242: {
00243: self::$_imports[$alias]=$className;
Stack Trace
#0 E:\Workspace\yii\framework\YiiBase.php(231): import()
#1 E:\Workspace\yii\framework\validators\CValidator.php(137): import()
#2 E:\Workspace\yii\framework\base\CModel.php(420): createValidator()
#3 E:\Workspace\yii\framework\db\ar\CActiveRecord.php(2183): Post->createValidators()
#4 E:\Workspace\yii\framework\db\ar\CActiveRecord.php(1039): CActiveRecordMetaData->getValidators()
#5 E:\Workspace\yii\framework\base\CModel.php(274): Post->getValidators()
#6 E:\Workspace\yii\framework\base\CModel.php(305): Post->getValidatorsForAttribute()
#7 E:\Workspace\yii\framework\web\helpers\CHtml.php(1025): Post->isAttributeRequired()
#8 E:\Workspace\blog\protected\views\post\_form.php(12): activeLabelEx()
#9 E:\Workspace\yii\framework\web\CBaseController.php(119): require()
#10 E:\Workspace\yii\framework\web\CBaseController.php(88): PostController->renderInternal()
#11 E:\Workspace\yii\framework\web\CController.php(701): PostController->renderFile()
#12 E:\Workspace\blog\protected\views\post\create.php(11): PostController->renderPartial()
#13 E:\Workspace\yii\framework\web\CBaseController.php(119): require()
#14 E:\Workspace\yii\framework\web\CBaseController.php(88): PostController->renderInternal()
#15 E:\Workspace\yii\framework\web\CController.php(701): PostController->renderFile()
#16 E:\Workspace\yii\framework\web\CController.php(640): PostController->renderPartial()
#17 E:\Workspace\blog\protected\controllers\PostController.php(74): PostController->render()
#18 E:\Workspace\yii\framework\web\actions\CInlineAction.php(32): PostController->actionCreate()
#19 E:\Workspace\yii\framework\web\CController.php(300): CInlineAction->run()
#20 E:\Workspace\yii\framework\web\filters\CFilterChain.php(129): PostController->runAction()
#21 E:\Workspace\yii\framework\web\filters\CFilter.php(41): CFilterChain->run()
#22 E:\Workspace\yii\framework\web\CController.php(952): CAccessControlFilter->filter()
#23 E:\Workspace\yii\framework\web\filters\CInlineFilter.php(59): PostController->filterAccessControl()
#24 E:\Workspace\yii\framework\web\filters\CFilterChain.php(126): CInlineFilter->filter()
#25 E:\Workspace\yii\framework\web\CController.php(283): CFilterChain->run()
#26 E:\Workspace\yii\framework\web\CController.php(257): PostController->runActionWithFilters()
#27 E:\Workspace\yii\framework\web\CWebApplication.php(332): PostController->run()
#28 E:\Workspace\yii\framework\web\CWebApplication.php(120): CWebApplication->runController()
#29 E:\Workspace\yii\framework\base\CApplication.php(133): CWebApplication->processRequest()
#30 E:\Workspace\blog\index.php(11): CWebApplication->run()
PostController.php
<?php
class PostController extends CController
{
const PAGE_SIZE=10;
/**
* @var string specifies the default action to be 'list'.
*/
public $defaultAction='list';
/**
* @var CActiveRecord the currently loaded data model instance.
*/
private $_model;
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'list' and 'show' actions
'actions'=>array('list','show'),
'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('*'),
),
);
}
/**
* Shows a particular model.
*/
public function actionShow()
{
$this->render('show',array('model'=>$this->loadPost()));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'show' page.
*/
public function actionCreate()
{
$model=new Post;
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save())
$this->redirect(array('show','id'=>$model->id));
}
$this->render('create',array('model'=>$model));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'show' page.
*/
public function actionUpdate()
{
$model=$this->loadPost();
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save())
$this->redirect(array('show','id'=>$model->id));
}
$this->render('update',array('model'=>$model));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'list' page.
*/
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadPost()->delete();
$this->redirect(array('list'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionList()
{
$criteria=new CDbCriteria;
$pages=new CPagination(Post::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$models=Post::model()->findAll($criteria);
$this->render('list',array(
'models'=>$models,
'pages'=>$pages,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$this->processAdminCommand();
$criteria=new CDbCriteria;
$pages=new CPagination(Post::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$sort=new CSort('Post');
$sort->applyOrder($criteria);
$models=Post::model()->findAll($criteria);
$this->render('admin',array(
'models'=>$models,
'pages'=>$pages,
'sort'=>$sort,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable
*/
public function loadPost($id=null)
{
if($this->_model===null)
{
if($id!==null || isset($_GET['id']))
$this->_model=Post::model()->findbyPk($id!==null ? $id : $_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
}
/**
* Executes any command triggered on the admin page.
*/
protected function processAdminCommand()
{
if(isset($_POST['command'], $_POST['id']) && $_POST['command']==='delete')
{
$this->loadPost($_POST['id'])->delete();
// reload the current page to avoid duplicated delete actions
$this->refresh();
}
}
}
Post-Model
<?php
class Post extends CActiveRecord
{
/**
* The followings are the available columns in table 'Post':
* @var integer $id
* @var string $title
* @var string $content
* @var string $contentDisplay
* @var string $tags
* @var integer $status
* @var integer $createTime
* @var integer $updateTime
* @var integer $commentCount
* @var integer $authorId
*/
const STATUS_DRAFT = 0;
const STATUS_PUBLISHED = 1;
const STATUS_ARCHIVED = 2;
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord 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 'Post';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
array('title', 'content', 'status', 'required'),
array('title', 'length', 'max' => 128 ),
array('status', 'in', 'range' => array(0,1,2)),
array('tags', 'match', 'pattern' => '/*[\w\s,]+$/', 'message' => 'Tags can only contain word characters'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
return array(
'author' => array( self::BELONGS_TO, 'User', 'authorId'),
'comments' => array( self::HAS_MANY, 'Comment', 'postId', 'order' => '??.createTime'),
'tagsFilter'=> array( self::MANY_MANY, 'Tag', 'PostTag(postId, tagId)',
'together' => true,
'joinType' => 'INNER JOIN',
'condition' => '??.name=:tag',
),
);
}
public function safeAttributes()
{
return array('title', 'content', 'status', 'tags');
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id'=>'Id',
'title'=>'Title',
'content'=>'Content',
'contentDisplay'=>'Content Display',
'tags'=>'Tags',
'status'=>'Status',
'createTime'=>'Create Time',
'updateTime'=>'Update Time',
'commentCount'=>'Comment Count',
'authorId'=>'Author',
);
}
public function getStatusOptions()
{
return array(
self::STATUS_DRAFT => 'Draft',
self::STATUS_PUBLISHED => 'Published',
self::STATUS_ARCHIVED => 'Archived',
);
}
public function getStatusText()
{
$options = $this->statusOptions;
return isset( $options[$this->status]) ? $options[$this->status] : "unknown ({$this->status})";
}
}
I do not understand where is the problem?!!?
please help
thx