Yii Framework Forum: Blog Tutorial - Create Post Fehlermeldung - Yii Framework Forum

Jump to content

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

Blog Tutorial - Create Post Fehlermeldung Rate Topic: -----

#1 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 26 July 2009 - 11:42 AM

Hi,
ich arbeite grade das Blog Tutorial durch und stoße auf komische Fehler und nicht aussagekräftige Fehlermeldungen.
Ich bin grad auf Seite 19 und erhalte folgender Fehlermeldung.

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})";
	}
}


kann mir einer bitte weiterhelfen.
Thx
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#2 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 26 July 2009 - 12:46 PM

Fehler gefunden
       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'),
                );
        }



       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'),
                );
        }


Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#3 User is offline   sebi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 06-October 08

Posted 26 July 2009 - 02:29 PM

Da wär ich jetzt aber auch nicht drauf gekommen ... die Fehlermeldung ist echt sehr aussagekräftig *ironie*
0

#4 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 27 July 2009 - 02:44 AM

Das fehlerhafte Array kam mir schon beim schreiben sehr eigenartig vor, dennoch wäre ich aufgrund der Fehlermeldung nicht drauf gekommen. Ich suche ja schon nach einem besseren Debug-Modus jedoch bis jetzt ohne Erfolg! >:(
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 27 July 2009 - 03:00 AM

Die Fehlermeldungen sind in der Regel schon sehr aussagekräftig, weil der komplette Callstack angezeigt wird. In deinem Fall hattest du da etwas Pech, grade weil das Schlüsselwort "require" nicht grad ins Auge sticht. Ansonsten kommt man damit aber schon recht gut klar, find ich.
0

#6 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 27 July 2009 - 04:38 AM

Ich bin gerade beim Portlet dran und nun meldet Yii folgendes zurück


Meine protected/components/UserMenu.php


<?php
class UserMenu extends Portlet
{
	public function init()
	{
		if (isset ($_POST['command']) && $_POST['command'] === 'logout')
		{
			Yii :: app()->user->logout();
			$this->controller->redirect(Yii :: app()->homeUrl);
		}

		$this->title = CHtml :: encode(Yii :: app()->user->name);
		parent :: init();
	}

	protected function renderContent()
	{
		$this->render('userMenu');
	}

}
?>



PHP Error
Description

include(Portlet.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Source File

E:\Workspace\yii\framework\YiiBase.php(316)

00304:      * @param string class name
00305:      * @return boolean whether the class has been loaded successfully
00306:      */
00307:     public static function autoload($className)
00308:     {
00309:         // use include so that the error PHP file may appear
00310:         if(isset(self::$_coreClasses[$className]))
00311:             include(YII_PATH.self::$_coreClasses[$className]);
00312:         else if(isset(self::$_classes[$className]))
00313:             include(self::$_classes[$className]);
00314:         else
00315:         {
00316: include($className.'.php');
00317:             return class_exists($className,false) || interface_exists($className,false);
00318:         }
00319:         return true;
00320:     }
00321: 
00322:     /**
00323:      * Writes a trace message.
00324:      * This method will only log a message when the application is in debug mode.
00325:      * @param string message to be logged
00326:      * @param string category of the message
00327:      * @see log
00328:      */

Stack Trace

#0 E:\Workspace\yii\framework\YiiBase.php(316): autoload()
#1 unknown(0): autoload()
#2 E:\Workspace\blog\protected\components\UserMenu.php(2): spl_autoload_call()
#3 E:\Workspace\yii\framework\YiiBase.php(231): require()
#4 E:\Workspace\yii\framework\web\CBaseController.php(137): import()
#5 E:\Workspace\yii\framework\web\CBaseController.php(153): SiteController->createWidget()
#6 E:\Workspace\blog\protected\views\layouts\main.php(33): SiteController->widget()
#7 E:\Workspace\yii\framework\web\CBaseController.php(119): require()
#8 E:\Workspace\yii\framework\web\CBaseController.php(88): SiteController->renderInternal()
#9 E:\Workspace\yii\framework\web\CController.php(642): SiteController->renderFile()
#10 E:\Workspace\blog\protected\controllers\SiteController.php(28): SiteController->render()
#11 E:\Workspace\yii\framework\web\actions\CInlineAction.php(32): SiteController->actionIndex()
#12 E:\Workspace\yii\framework\web\CController.php(300): CInlineAction->run()
#13 E:\Workspace\yii\framework\web\CController.php(278): SiteController->runAction()
#14 E:\Workspace\yii\framework\web\CController.php(257): SiteController->runActionWithFilters()
#15 E:\Workspace\yii\framework\web\CWebApplication.php(332): SiteController->run()
#16 E:\Workspace\yii\framework\web\CWebApplication.php(120): CWebApplication->runController()
#17 E:\Workspace\yii\framework\base\CApplication.php(133): CWebApplication->processRequest()
#18 E:\Workspace\blog\index.php(11): CWebApplication->run()




Wundern tue ich mich über folgende Zeile

include(Portlet.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Source File


das müsste doch hier über den autoload-er funktionieren
class UserMenu extends Portlet

Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#7 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 27 July 2009 - 04:42 AM

Wo liegt denn dein Portlet.php? Hast du das entsprechende Verzeichnis im 'import'-Bereich deiner Konfiguration?
0

#8 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 27 July 2009 - 05:12 AM

Fehler gefunden ;)
Bin grad auf Seite 37 im Blog Tutorial und bin davon ausgegangen das die Klasse schon in Yii automatisch enthalten ist.
Habe sie nun nachträglich in protected/components/Portlet.php angelegt
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#9 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 27 July 2009 - 05:15 AM

Wenn man sich die Kommentare auf
http://www.yiiframew...og/portlet.menu
durchliest, sieht man das mehrere Leute Probleme mit dem Tutorial - Portlet haben.
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#10 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 27 July 2009 - 05:42 AM

Hmm. Aber eigentlich stehts doch ne Seite vorher, dass man die Portlet-Klasse anlegen muss:
http://www.yiiframew...og/portlet.base

Evtl. sollte man das dort noch deutlicher machen.
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