Nie Moze Znalesc Klasy Controller

Witam,

Na moim komputerze blog ktory pisze dziala dobrze, jednak problem pojawia sie kiedy daje go na serwer http://mrgh0st.iscool.pl/.

Fatal error: Class ‘Controller’ not found in /home/sites/m/mr/mrg/mrgh0st.iscool.pl/protected/controllers/PostyController.php on line 3

Taki blad dostaje, ktos sie domysla co jest zle? Pliki .htacces sa takie jakie byly, tylko w glownym inny (wg tego co gdzies znalazlem na yii czy w ktoryms tutku o url)

Upewnij się, że w /protected/config/main.php w sekcji import masz dodane automatyczne ładowanie klasy Controller.php.

Coś w rodzaju:




'import' => array(

    ...

    'application.components.*',

    ...

);



Sprawdź wielkość liter - czy plik i klasa nazywa się Controller? A może controller?

Wszystko się zgadza, już pisałem że u mnie na komputerze (na xamppie, windows 7 pro) działa wszystko dobrze.

A na http://mrgh0st.ovh.org/ znowu inny problem… Wszystko to serwery darmowe.

Cześć,

  1. wykonaj test wymagań frameworka yii, powinien być w katalogu requirements w paczce z yii.

  2. jeżeli kopiujesz z lokala na serwer wyczyść katalog assets i runtime

  3. ustaw prawa zapisu do assets i runtime.

  4. sprawdż wersje php.

  5. swój controller rozszerzasz z kontrolera Controller, który w domyślnej konfiguracji powinien być w katalogu components, powinienieć wtedy dokonać importu w pliku konfiguracyjnym




'import' => array(

        'application.models.*',

        'application.components.*',

    ),



  1. jeżeli nie masz katalogu components lub klasy Controller, rozszerzaj swoją klasę kontrolera z klasy CController

8 jak sobie nie poradzisz, wklej kod pliku index.php, main.php, PostController.php

powodzenia

http://mrgh0st.iscool.pl/yii.png <- requirements zrzut ekranu

Wersji php nie za bardzo wiem jak sprawdzic (phpinfo() nie dziala :confused: gowniany cos host…)

EDIT: sprawdzilem 5.2.17

Tamte foldery tez zrobilem tak jak mowilem, plik Controller.php jest gdzie powinien byc.

Kod pliku index.php


<?php


// change the following paths if necessary

$yii=dirname(__FILE__).'/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';


// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


require_once($yii);

Yii::createWebApplication($config)->run();



main.php


<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Mr. Gh0st Blog',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),

	'modules'=>array(

		// uncomment the following to enable the Gii tool

	/*

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'niepodam',

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		), */


	), 

	'defaultController'=>'Posty',

	// application components

	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format


		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		/*

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		), */

		// uncomment the following to use a MySQL database

		

		'db'=>array(

			'connectionString' => 'mysql:host=serwer.pl;dbname=baza',

			'emulatePrepare' => true,

			'username' => 'xxx',

			'password' => 'xxx',

			'charset' => 'utf8',

		),

		

		'errorHandler'=>array(

			// use 'site/error' action to display errors

			'errorAction'=>'site/error',

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				

				array(

					'class'=>'CWebLogRoute',

				),

				

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'mail...xx@.pl',

	),

);

PostyController.php


<?php


class PostyController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';

	private $id;

	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'postOnly + delete', // we only allow deletion via POST request

		);

	}


	/**

	 * 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 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'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('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	public function actionView($id)

	{

		$post=$this->loadModel($id);

		$this->id=$id;

		$this->render('view',array(

			'model'=>$post,

			'komentarz'=>$this->nowy($post),

		));

	}

	protected function nowy($post)

	{

		$comment = new Komentarze;

		if (isset($_POST['Komentarze'])) {

			$comment->attributes=$_POST['Komentarze'];

			if($this->addComment($comment)){

				Yii::app()->user->setFlash('commentSubmitted','Dziekuje za wyslanie komentarza');				

				$this->refresh();	

			} else echo "blad";

		}

		return $comment;

	}

	public function addComment($comment)

	{

		$comment->ID_Postu=$this->id;

		return $comment->save();	

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		$model=new Posty;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Posty']))

		{

			$model->attributes=$_POST['Posty'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->ID));

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Posty']))

		{

			$model->attributes=$_POST['Posty'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->ID));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		$this->loadModel($id)->delete();


		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

		if(!isset($_GET['ajax']))

			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$criteria=new CDbCriteria(array(

			'order'=>'ID DESC',

			'with'=>'CommentCount',));

		if(isset($_GET['tag']))

			$criteria->addSearchCondition('tag',$_GET['tag']);

		$dataProvider=new CActiveDataProvider('Posty',

		array(

		'pagination'=>array(

		'pageSize'=>10,),

		'criteria'=>$criteria,));

		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new Posty('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Posty']))

			$model->attributes=$_GET['Posty'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}


	/**

	 * 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 $id the ID of the model to be loaded

	 * @return Posty the loaded model

	 * @throws CHttpException

	 */

	public function loadModel($id)

	{

		$model=Posty::model()->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param Posty $model the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='posty-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}

	protected function afterDelete()

	{

		parent::afterDelete();

		Komentarze::model()->deleteAll('ID_Postu='.$this->id);

	}


}



Sprawdź jeszcze co pisał wcześniej kolega z wielkością liter w nazwach plików controller i Controller to w php nie to samo, a zdarzyło mi się, że podczas kopiowania przez ftp wszystkie duże litery zostały zamienione na małe i był podobny problem.

  1. Daj jeszcze screen zawartośći katalogu components i klasę Controller.php

  2. na który serwer mam patrzeć z tymi błędami http://mrgh0st.iscool.pl/. czy na ovh.org ?

  3. popatrzyłem jeszcze na forach i wskazywali na problem z htaccess oraz prawa katlogu protected (z podkatalogami) i jego właściciela.

  1. http://mrgh0st.iscool.pl/controller.png

  2. mrgh0st.iscool.pl

  3. tez o tym myślałem… nawet te pliki htacces co tam były usunąłem i nic nie dało, a prawa do plików są 755

Zaraz spróbuje zrobić tam nową subdomene i wrzucić jakis przykładowy projekt co już jest w paczce z frameworkiem

Niestety… Tez ten sam blad… :confused:

  1. Spróbuj zmienić PostyController extends z Controller na CController.

  2. W jednym poście znalazłem podobny problem i można wykonać import Yii::import(‘appalication.components.controller’, true) ale poczytaj api bo tego nie używałem.

  3. Miałeś jeszcze podesłać kod controller.php

  4. sprawdź logi serwera apache, może tam będzie coś napisane.

  5. jak nie dasz rady uruchomić to pisz na priv, zrobię ci konto testowe u siebie na serwerze, u mnie wszystko dział ok, może znajdziemy w czym problem.

No i jeszcze zapomniałem, jeżeli pliki mają atrybuty jak piszesz 755 to sprawdź czy katalog ma poprawne atrybuty, na ale wtedy to w logach apache będzie.

  1. Juz tak wczesniej zrobilem i nic nie pomoglo…

  2. w Controller.php nic nie zmienialem, jest taki sam jak w paczce.

  3. Jakbym wiedzial jak na darmowym serwerze sprawdzic logi to bym sprawdzil chetnie :)

Cos mi sie wydaje ze cos tam oni blokuja bo to ‘darmowe’, moze sprobujcie sami na tym serwisie (friko.pl zaklada sie konto a potem tam sie wszystko ustawia)

Już wiem co było nie tak, na serwerze nie było mod_rewrite, trzeba było użyć showscriptname (czy jakos tak) w konfiguracji i po kłopocie, tylko index.php jest.