Can't figure out, Basic begginer error after creating Crud with gii

i just can’t figure out what i’m doing wrong,i’m following the early tutorials and trying to use gii to generates some crud, but it seems every code i generate throught there gives out the same problem. if i just copy classes from the demos they work great. using 1.1.5

i’m getting really frustrated. i think its some really basic:

bootstrap




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




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

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


require_once($yii);

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



eror code when i try to access

index.php?r=anything i generate




00383:      * @return boolean whether the class has been loaded successfully

00384:      */

00385:     public static function autoload($className)

00386:     {

00387:         // use include so that the error PHP file may appear

00388:         if(isset(self::$_coreClasses[$className]))

00389:             include(YII_PATH.self::$_coreClasses[$className]);

00390:         else if(isset(self::$classMap[$className]))

00391:             include(self::$classMap[$className]);

00392:         else

00393:         {

00394:             if(strpos($className,'\\')===false)

00395: include($className.'.php');

00396:             else  // class name with namespace in PHP 5.3

00397:             {

00398:                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

00399:                 if(($path=self::getPathOfAlias($namespace))!==false)

00400:                     include($path.'.php');

00401:                 else

00402:                     return false;

00403:             }

00404:             return class_exists($className,false) || interface_exists($className,false);

00405:         }

00406:         return true;

00407:     }




What does the Gii generator output look like?

this




<?php


class ConfigUsuariosController 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';


	/**

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

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

				'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)

	{

		echo 'TESTE OMOABORINGO!!![-!-]';

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

			'model'=>$this->loadModel($id),

		));

	}


	/**

	 * Creates a new model.

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

	 */

	public function actionCreate()

	{

		$model=new ConfigUsuarios;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			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['ConfigUsuarios']))

		{

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

			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 'index' page.

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

	 */

	public function actionDelete($id)

	{

		if(Yii::app()->request->isPostRequest)

		{

			// we only allow deletion via POST request

			$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'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('ConfigUsuarios');

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

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new ConfigUsuarios('search');

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

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

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


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

	 */

	public function loadModel($id)

	{

		$model=ConfigUsuarios::model()->findByPk((int)$id);

		if($model===null)

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

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param CModel the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

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

		{

			echo CActiveForm::validate($model);

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

		}

	}


 	protected function teste($model)

	{

		echo 'world, don\'t hold back';

	}

}




weird thought i’m just testing here and i’m looking at some of the demos and they have mostly start like this:




class GameController extends CController{



why does the Gii generated code inherits from Controller?

That’s because there is a Controller class in your protected/components directory which is derived from CController.

Take a look. A good example of how to tuck common code in a parent class. ;)

You should have a ‘Controller’ in your application’s components directory which extends CController.

This allows you to customize all the controllers within your site by updating that one base Controller if needed (among other things).

só there it is, i should have looked harder at the blog demo all along…

and here i was thinking i was miss configurating some path…

ok so this can be marked as [SOLVED] :D

not to look a gift horse on the mouth, but i’ve had some hard time coming up with the right structure of folders and needed files for the tutorial, i don’t know if i’m missing something, but i didn’t want to copy paste the blog folder. :confused:

Thank you people!

If you use the yiic command to create your new webapp, it will generate the proper base file structure for you.

From your command prompt in the webroot directory:




$ path/to/Yii/framework/yiic webapp new_site_name



See:

Creating Webapp Doc

That will create the webapp configured to use the framework directory that you ran the yiic webapp create from, giving you the core site config and components etc. You will need to set the file permissions for the assets and runtime folders after that, but otherwise it’ll be good to go.