woyuge 2012-09-07 17:49:07 4114次浏览 0条回复 0 0 0
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'); ?>&nbsp;&nbsp;<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在官网的回答

  1. 在 $campaigns = new Campaigns(); // main 之后加上 $campaigns->info = new CampaignsInfo();

  2. echo CActiveForm::validate($campaigns); 改为 echo CActiveForm::validate(array($campaigns, $campaigns->info));

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册