我按照指南使用两个模型(用户,用户信息)制作注册表单,但是当我查看注册表单时出现警告(包括(data.php)[function.include]:无法打开流:没有这样的文件或目录)弹出,我真的不明白是什么导致了这个警告。这是我的代码:
1. Register action:
public function actionRegister(){
$user=new User;
$user_info=new UserInfo;
if(isset($_POST['User'],$_POST['UserInfo'])){
$user->attributes=$_POST['User'];
$user_info->attributes=$_POST['UserInfo'];
$valid=$user->validate();
$valid=$user_info->validate() && $valid;
if($valid){
$user->save(false);
$user_info->save(false);
$this->redirect(array('index'));
}
}
$this->render('register', array('user'=>$user,'user_info'=>$user_info));
}
2. Register view:
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>$this->createUrl('Site/Register'),
'enableClientValidation'=>true,
'enableAjaxValidation'=>false,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
'htmlOptions'=>array('enctype'=>'multipart/form-data')
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary(array($user,$user_info)); ?>
<div class="row">
<?php echo $form->labelEx($user,'username'); ?>
<?php echo $form->textField($user,'username',array('size'=>60,'maxlength'=>300)); ?>
<?php echo $form->error($user,'username'); ?>
</div>
3.PHP Warning:
include(data.php) [<a href='function.include'>function.include</a>]: failed
to open stream: No such file or directory
(C:\wamp\www\Yii-new\framework\YiiBase.php:427)
Stack trace:
#0 C:\wamp\www\Yii-new\framework\validators\CValidator.php(186): import()
#1 C:\wamp\www\Yii-new\framework\base\CModel.php(287): createValidator()
#2 C:\wamp\www\Yii-new\framework\base\CModel.php(260):
UserInfo->createValidators()
#3 C:\wamp\www\Yii-new\framework\web\widgets\CActiveForm.php(506):
UserInfo->getValidators()
#4 C:\wamp\www\Yii-new\project2\protected\views\site\register.php(50):
CActiveForm->error()
#5 C:\wamp\www\Yii-new\framework\web\CBaseController.php(126): require()
#6 C:\wamp\www\Yii-new\framework\web\CBaseController.php(95):
SiteController->renderInternal()
#7 C:\wamp\www\Yii-new\framework\web\CController.php(869):
SiteController->renderFile()
#8 C:\wamp\www\Yii-new\framework\web\CController.php(782):
SiteController->renderPartial()
#9
C:\wamp\www\Yii-new\project2\protected\controllers\SiteController.php(109):
SiteController->render()
#10 C:\wamp\www\Yii-new\framework\web\actions\CInlineAction.php(49):
SiteController->actionRegister()
#11 C:\wamp\www\Yii-new\framework\web\CController.php(308):
CInlineAction->runWithParams()
#12 C:\wamp\www\Yii-new\framework\web\CController.php(286):
SiteController->runAction()
#13 C:\wamp\www\Yii-new\framework\web\CController.php(265):
SiteController->runActionWithFilters()
#14 C:\wamp\www\Yii-new\framework\web\CWebApplication.php(282):
SiteController->run()
#15 C:\wamp\www\Yii-new\framework\web\CWebApplication.php(141):
CWebApplication->runController()
#16 C:\wamp\www\Yii-new\framework\base\CApplication.php(180):
CWebApplication->processRequest()
#17 C:\wamp\www\Yii-new\project2\index.php(13): CWebApplication->run()
REQUEST_URI=/Yii-new/project2/site/register
in C:\wamp\www\Yii-new\project2\protected\views\site\register.php (50)
in C:\wamp\www\Yii-new\project2\protected\controllers\SiteController.php
(109)
in C:\wamp\www\Yii-new\project2\index.php (13)
[1]: http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/