yii-的relation-ajax校验问题/ [ 新手入门 ]
class Campaigns
public function relations()
return array(
'info' => array(self::HAS_ONE, 'CampaignsInfo', 'camp_id', 'joinType' => 'INNER JOIN'),
'free_campaigns' => array(self::HAS_ONE, 'FreeCampaigns', 'camp_id'),
);
class controller
public function actionCreate()
{
$campaigns = new Campaigns(); // main
$campaignsInfo = $campaigns->info;
if(isset($_POST['ajax']) && $_POST['ajax']==='freecmp-form')
{
echo CActiveForm::validate($campaigns);
//if(CActiveForm::validate($campaignsInfo) != '')
//{
echo CActiveForm::validate($campaigns->info);
//}
Yii::app()->end();
}
view
<?php echo $form->textField($cmp->info,'quota'); ?> <span style='color:red'><?php echo $form->error($cmp->info,'quota'); ?></span>
问题:
Fatal error: Call to a member function getValidators() on a non-object in /home/seven/third-api/php-library/yii-1.1.5.r2654/framework/web/helpers/CHtml.php on line 1732
我怎样才能在Creat事件触发的同事也验证 CampaignsInfo的规则呢?
以下是lightman在官网的回答
在 $campaigns = new Campaigns(); // main 之后加上
$campaigns->info = new CampaignsInfo();
echo CActiveForm::validate($campaigns);
改为echo CActiveForm::validate(array($campaigns, $campaigns->info));
共 0 条回复
没有找到数据。
woyuge 广东
注册时间:2012-08-10
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱40
- 威望0
- 积分40