B
B
Bombadile2014-09-11 17:23:49
Yii
Bombadile, 2014-09-11 17:23:49

How to fix Undefined index: ActiveForm error in compiled Smarty template in Yii2?

The Smarty template renders a form:

{use class='yii\widgets\ActiveForm' type='block'}
{ActiveForm assign='form' id='login-form' action='/form-handler' options=['class' => 'form-horizontal']}
    {$form->field($model, 'firstName')}
    <div class="form-group">
        <div class="col-lg-offset-1 col-lg-11">
            <input type="submit" value="Login" class="btn btn-primary" />
        </div>
    </div>
{/ActiveForm}

The Smarty template file is saved. This page of the site in the browser is updated - everything is fine. But when the page is refreshed again, an error occurs: Undefined index: ActiveForm. That is, when you re-access this page, the code is taken from the compiled template file, in which the following code:
<?php
        $_smarty_tpl->getGlobal('_viewRenderer')->widgets['blocks']['ActiveForm'] = 'yii\widgets\ActiveForm';
        try {
          $_smarty_tpl->registerPlugin('block', 'ActiveForm', [$_smarty_tpl->getGlobal('_viewRenderer'), '_widget_block__ActiveForm']);
        } catch (SmartyException $e) {
          /* Ignore already registered exception during first execution after compilation */
        }
        ?>   
        <?php $_smarty_tpl->smarty->_tag_stack[] = array('ActiveForm', array('assign' => 'form', 'id' => 'login-form', 'action' => '/backend/login/', 'options' => array('class' => 'uk-panel uk-panel-box uk-form')));
        $_block_repeat = true;
        echo $_smarty_tpl->smarty->registered_plugins['block']['ActiveForm'][0][0]->_widget_block__ActiveForm(array('assign' => 'form', 'id' => 'login-form', 'action' => '/backend/login/2', 'options' => array('class' => 'uk-panel uk-panel-box uk-form')), null, $_smarty_tpl, $_block_repeat);
        while ($_block_repeat) {
          ob_start(); ?>

      <?php echo $_smarty_tpl->tpl_vars['form']->value->field($_smarty_tpl->tpl_vars['model']->value, 'username')->textInput(array('placeholder' => $_smarty_tpl->tpl_vars['model']->value->getAttributeLabel('username'), 'class' => 'form-group5'))->label(false); ?>

      <?php echo $_smarty_tpl->tpl_vars['form']->value->field($_smarty_tpl->tpl_vars['model']->value, 'password')->passwordInput(array('placeholder' => $_smarty_tpl->tpl_vars['model']->value->getAttributeLabel('password')))->label(false); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grechushnikov, 2015-04-22
@maxyc_webber

off-topic.
what a quiet horror. why do you complicate your life with third-party template engines? php is great as a template engine. in conjunction with yii even more so. if you have already learned the smart workbench, then it is even easier for him to learn php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question