منبع اصلی نوشتار زیر در این لینک قرار دارد

مثال برای کلاس CFrom

CForm در Yii. مدل:

//models/SummariesForm.php

class SummariesForm extends CFormModel
{
    public $account;
    public $userToken;
    public $year;

    public function rules () {...}

    public function fetchSummary () {...}

    static public function getYearOptions () {...}
}

کنترلر:

//controllers/AccountController.php

class AccountController extends CController
{
    public $layout = 'extranet';

    public function actionSelect ()
    {
        $model = new SummariesForm();

        // retrieve account
        require_once 'AccountCookie.php';

        /*
         *
         * Here, I insert the account directly into the
         * model used to build the form, but $model isn't
         * available to selectForm.php. So, it doesn't
         * become part of the form, and this $model doesn't
         * persist to actionSummaries().
         * 
         */
        $model->account = AccountCookie::decrypt();
        if ($model->account === false) {
            throw new Exception('Unable to retrieve account.');
        }

        $form = new CForm('application.views.account.selectForm', $model);
        $this->render('select', array(
            'form'    => $form,
            'account' => $model->account,
        ));
    }
    }

}

ویو:

//views/account/select.php

<?php
$this->pageTitle=Yii::app()->name;
?>

<div class="form">
    <?php echo $form->render(); ?>
</div>

فایل تنظیمات CForm:

//views/account/selectForm.php

return array(
    'title' => 'Select year',
    'action' => Yii::app()->createUrl('Account/Summaries'),
    'method' => 'post',

    'elements' => array(
        'account' => array(
            'type'  => 'hidden',
            'value' => $account,
        ),
        'userToken' => array(
            'type'  => 'hidden',
            'value' => /* get token */,
        ),
        'year' => array(
            'type'  => 'dropdownlist',
            'items' => SummariesForm::getYearOptions(),
        ),
    ),

    'buttons' => array(
        'view' => array(
            'type'  => 'submit',
            'label' => 'View summaries',
        ),
    ),
);

essential-strategy.com/activeform

The post مثال برای کلاس CFrom appeared first on دست نوشته های یک تازه کار.



برچسب ها : , , ,

به سیاره لینوکس امتیاز دهید

به اين صفحه امتياز دهيد