Yii Framework Forum: Create and Update views not functioning - Yii Framework Forum

Jump to content

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

Create and Update views not functioning Rate Topic: -----

#1 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 23 April 2010 - 09:37 AM

I have an Update and create form that does not want to work

It looks like this


<div class="form">

<?php

$form=$this->beginWidget('CActiveForm', array(
	'id'=>'users-form',
	'enableAjaxValidation'=>true,
));


?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'username'); ?>
		<?php echo $form->textField($model,'username',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'username'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>150)); ?>
		<?php echo $form->error($model,'password'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'surname'); ?>
		<?php echo $form->textField($model,'surname',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'surname'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>150)); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>


	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->



If I run the code I get the following error

PHP Error
Description

include(username, password, name, surname, email,createdate,moddate.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Source File

/var/www/mysite/yii-1.1.1.r1907/framework/YiiBase.php(338)

00326:      * @param string class name
00327:      * @return boolean whether the class has been loaded successfully
00328:      */
00329:     public static function autoload($className)
00330:     {
00331:         // use include so that the error PHP file may appear
00332:         if(isset(self::$_coreClasses[$className]))
00333:             include(YII_PATH.self::$_coreClasses[$className]);
00334:         else if(isset(self::$_classes[$className]))
00335:             include(self::$_classes[$className]);
00336:         else
00337:         {
00338: include($className.'.php');
00339:             return class_exists($className,false) || interface_exists($className,false);
00340:         }
00341:         return true;
00342:     }
00343: 
00344:     /**
00345:      * Writes a trace message.
00346:      * This method will only log a message when the application is in debug mode.
00347:      * @param string message to be logged
00348:      * @param string category of the message
00349:      * @see log
00350:      */

Stack Trace

#0 /var/www/mysite/yii-1.1.1.r1907/framework/YiiBase.php(338): autoload()
#1 /var/www/mysite/yii-1.1.1.r1907/framework/YiiBase.php(243): autoload()
#2 /var/www/mysite/yii-1.1.1.r1907/framework/validators/CValidator.php(150): import()
#3 /var/www/mysite/yii-1.1.1.r1907/framework/base/CModel.php(239): createValidator()
#4 /var/www/mysite/yii-1.1.1.r1907/framework/base/CModel.php(213): User->createValidators()
#5 /var/www/mysite/yii-1.1.1.r1907/framework/base/CModel.php(257): User->getValidators()
#6 /var/www/mysite/yii-1.1.1.r1907/framework/web/helpers/CHtml.php(1109): User->isAttributeRequired()
#7 /var/www/mysite/yii-1.1.1.r1907/framework/web/widgets/CActiveForm.php(362): activeLabelEx()
#8 /var/www/mysite/protected/backend/views/user/_form.php(18): CActiveForm->labelEx()
#9 /var/www/mysite/yii-1.1.1.r1907/framework/web/CBaseController.php(119): require()
#10 /var/www/mysite/yii-1.1.1.r1907/framework/web/CBaseController.php(88): UserController->renderInternal()
#11 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(742): UserController->renderFile()
#12 /var/www/mysite/protected/backend/views/user/create.php(15): UserController->renderPartial()
#13 /var/www/mysite/yii-1.1.1.r1907/framework/web/CBaseController.php(119): require()
#14 /var/www/mysite/yii-1.1.1.r1907/framework/web/CBaseController.php(88): UserController->renderInternal()
#15 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(742): UserController->renderFile()
#16 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(681): UserController->renderPartial()
#17 /var/www/mysite/protected/backend/controllers/UserController.php(74): UserController->render()
#18 /var/www/mysite/yii-1.1.1.r1907/framework/web/actions/CInlineAction.php(32): UserController->actionCreate()
#19 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(300): CInlineAction->run()
#20 /var/www/mysite/yii-1.1.1.r1907/framework/web/filters/CFilterChain.php(129): UserController->runAction()
#21 /var/www/mysite/yii-1.1.1.r1907/framework/web/filters/CFilter.php(41): CFilterChain->run()
#22 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(993): CAccessControlFilter->filter()
#23 /var/www/mysite/yii-1.1.1.r1907/framework/web/filters/CInlineFilter.php(59): UserController->filterAccessControl()
#24 /var/www/mysite/yii-1.1.1.r1907/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter()
#25 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(283): CFilterChain->run()
#26 /var/www/mysite/yii-1.1.1.r1907/framework/web/CController.php(257): UserController->runActionWithFilters()
#27 /var/www/mysite/yii-1.1.1.r1907/framework/web/CWebApplication.php(320): UserController->run()
#28 /var/www/mysite/yii-1.1.1.r1907/framework/web/CWebApplication.php(120): CWebApplication->runController()
#29 /var/www/mysite/yii-1.1.1.r1907/framework/base/CApplication.php(135): CWebApplication->processRequest()
#30 /var/www/mysite/backend.php(12): CWebApplication->run()



I however noticed by removing the below my code works fine, just without any form fields, I have no idea what I'm doing wrong.

<div class="row">
		<?php echo $form->labelEx($model,'username'); ?>
		<?php echo $form->textField($model,'username',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'username'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'password'); ?>
		<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>150)); ?>
		<?php echo $form->error($model,'password'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'surname'); ?>
		<?php echo $form->textField($model,'surname',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'surname'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'email'); ?>
		<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>150)); ?>
		<?php echo $form->error($model,'email'); ?>
	</div>



Please help, I'm stuck :-(
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 23 April 2010 - 09:46 AM

Could you show us your model rules() method?
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#3 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 23 April 2010 - 09:59 AM

View PostVince., on 23 April 2010 - 09:46 AM, said:

Could you show us your model rules() method?


public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, password, name, surname, email', 'required'),
			array('username, name, surname', 'length', 'max'=>50),
			array('password', 'length', 'max'=>50),
			array('email','length','max'=>150),
			array('email','email'),
			array('username, password, email', 'required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id','username, password, name, surname, email,createdate,moddate', 'safe', 'on'=>'search'),
		);
	}

0

#4 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 23 April 2010 - 10:19 AM

Problem fixed, the error was in the rules, the extra ',' after id caused the error

array('id','username, password, name, surname, email,createdate,moddate', 'safe', 'on'=>'search'),

should be

array('id,username, password, name, surname, email,createdate,moddate', 'safe', 'on'=>'search'),

The problem existed between keyboard and chair ;-)






www.techportal.co.za
0

#5 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 23 April 2010 - 12:07 PM

Yep happens to all of us.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
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