doulai8128 2014-02-18 19:02
浏览 41

Yii Cactive表格

Hi I want to create a contact form in YII view. i am using CACtive forms but the problem is it requires a model, I don't have a model, I am just calling a view without any model. below is my code

$form = $this->beginWidget('CActiveForm', array(
  echo $form->labelEx('name_of_organization');

gives me the error Missing argument 2 for CActiveForm::labelEx(),

  • 写回答

1条回答 默认 最新

  • doucai6663 2014-02-18 19:36

    Well, if I guess correctly, you don't have any table to store your data and you do not need any interaction between your model and database, and you just want to use ActiveForm features without a model. It's impossible. But there is a trick to solve this problem. You can easily create a fake model and use it into your ActiveForm.

    First, Create a model in your models directory, BUT NOT AN ORDINARY MODEL. Like below:

    class FakeModel extends CFormModel{
    public $organizationName; //for example!
    public $fullname; // for example!!
    public $email; // for example!!!
    public function rules() {
        return array(
    public function attributeLabels() {
        return array(
            'email'=>'E-Mail Address',
            'organizationName'=>'Organization Name',
            'fullname'=>'Full Name',

    Note that, FakeModel extended the CFormModel class.

    Umm, Now you have a model just like other AR's models :) You can send this model into your ActiveForm, even perform validation in your model.

    $fakeModel=new FakeModel();
    //for validation

    As you can see, there is no interaction between your ActiveForm and database. Easily pass your $fakeModel as the model(second parameter) in your CActiveForm.

    UPDATE As you probably know, the real name is 'CFormModel'.

    I hope it help :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥40 matlab简单代码修改补充
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题
  • ¥20 oracle RAC 怎么配置啊,配置
  • ¥15 excel 日常使用中出现问题