folder for view template not found - zend-framework

I'm again searching for the best way to do. I tried a bit with partial-views, it doesn't work the template isn't found.
Here what I did:
snippet show.phtml
foreach ($dcls as $dcl) :
//var_dump(get_object_vars($importdcls));
?>
<tr>
<td><?= $dcl->DCLID?></td>
<td><?= $dcl->Part_Number?></td>
<td><?= $dcl->Pad_Number?></td>
<td><?= $dcl->Pad_Issue?></td>
<td><?= $dcl->Pad_App?></td>
</tr>
<?php echo $this->partial('showpartial', ['pads'=>$pad]);?>
<?php endforeach; ?>
I saved the partial in the same folder as the show.phtml
My showpartial.phtml
<?php
$this->title = "Partial";
$this->headTitle($this->titel);
?>
<p></p>
<tr>
<td><?= $pad->DCLID?></td>
<td><?= $pad->Part_Number?></td>
<td><?= $pad->Pad_Number?></td>
<td><?= $pad->Pad_Issue?></td>
<td><?= $pad->Pad_App?></td>
</tr>
In my controller I give two parameters to the view:
return new ViewModel([
'dcls' => $this->table->fetchPartDcl($id),
'pads' => $this->padtable->fetchPadPart($id),
]);
here also my view_manager configuration:
'view_manager' => [ //templates für den view_manager
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404', //Skript für 404 Fehler
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/layoutlogin' => __DIR__ . '/../view/layout/layoutlogin.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
The error I get:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "showpartial"; resolver could not resolve to a file
because of the error message I think I have still an understanding problem. Here some questions:
What is to do to find the template in this folder, I would expect ZF to find it anyway, because it is in the same folder?
Where would you save the partials? In the view folder of the route or somewhere else. What is recommended?
Is the main idea of using partial in this case a good one?

ok I added a folder partial under my view module folder. Now it works.

Related

put submit button in Tabs::widget in yii2

I have a Tabs::widget that all settings are located in different tabs in a ActiveForm and admin can set config in each tab and once submit.(multiple forms in one widget )
in setting view :
<?php $form = ActiveForm::begin(); ?>
<?php
echo \yii\jui\Tabs::widget([
'headerOptions' => ['class' => 'tabs'],
'itemOptions' => ['tag' => 'div'],
'items' => [
[
'label' => 'serverSetting',
'content' => $this->render('serverSetting', ['model' => $model, 'form' => $form]),
'active' => true
],
[
'label' => 'emailSetting',
'content' => $this->render('emailSetting', ['model' => $model, 'form' => $form]),
],
[
'label' => 'smsSetting',
'content' => $this->render('smsSetting', ['model' => $model, 'form' => $form]),
],
],
]);
?>
<div class="btnForm">
<?= Html::submitButton(Yii::t('app', 'ثبت', ['class' => 'btn btn-primary', 'name' => ''])) ?>
</div>
<?php ActiveForm::end(); ?>
in view of one of the tabs (smsServer view):
<?php
use yii\helpers\Html;
use app\components\ActiveForm;
?>
<div class="user-form">
<?= $form->field($model, 'login')->textInput(['placeholder' => 'host']) ?>
<?= $form->field($model, 'password1')->textInput(['placeholder' => 'username']) ?>
<?= $form->field($model, 'wsdl')->textInput(['placeholder' => 'password']) ?>
<?= $form->field($model, 'from1')->textInput(['placeholder' => 'port']) ?>
</div>
in controller :
public function actionSetting()
{
$model = new Setting();
$model->setAttributes(Yii::$app->params, false);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
file_put_contents(Yii::getAlias('#app/config') . DIRECTORY_SEPARATOR . 'extra_params.php', base64_encode(serialize($model->attributes)));
}
return $this->render('setting', [
'model' => $model,
]);
}
My form and submit button do not work. where is my problem?
Seems you don't have an ActiveForm::end()
.......
<div class="btnForm">
<?= Html::submitButton(Yii::t('app', 'ثبت', ['class' => 'btn btn-primary'])) ?>
</div>
<?php ActiveForm::end(); ?>
and for debugging don't suppress the name of button
So I found my answer. My validation was false.
in rule():
[['login', 'wsdl', 'password','from1'], 'required',],
But I post form without filled all fields.
I changed to
[['login',], 'required',],
[['login', 'wsdl', 'password',from1'], 'safe',],

How to add Bootstrap Modal in Yii2?

<div class="create-job-form">
<?php
Modal::begin([
'header' => '<h4>Job Created</h4>',
'id' => 'jobPop',
'size' => 'modal-lg',
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<table width="5">
<?php $form = ActiveForm::begin(); ?>
<fieldset>
<legend>Order Details</legend>
<td>
<tr> <?= Html::activeHiddenInput($model, 'job_code', ['value' => rand(1, 10000)]) ?> </tr>
</td>
<td>
<tr><?= $form->field($model, 'job_description')->textInput(['maxlength' => true]) ?></tr>
</td>
<td>
<tr>
<?= $form->field($model, 'approved_date')->widget(
DatePicker::className(), [
// inline too, not bad
'inline' => true,
// modify template for custom rendering
'template' => '{input}',
'clientOptions' => [
'autoclose' => false,
'format' => 'dd-M-yyyy'
]
]); ?>
</tr>
</td>
<td>
<tr><?= $form->field($model, 'estimated_time')->dropDownList(['24hrs' => '24 Hours', '48hrs' => '48 Hours', '2-3d' => '2-3 Days', '3-4d' => '3-4 Days', '4-5d' => '4-5 Days', '5-6d' => '5-6 Days'], ['prompt' => 'Select Time']) ?></tr>
</td>
</fieldset>
</table>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'id' => 'jobPop']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
$script = <<< JS
$(function() {
$('#jobPop').click(function () {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
});
});
JS;
$this->registerJs($script);
?>
This is my form, I'm trying to get Modal when click on create button, so that View will be on Modal. what i'm doing wrong?
I need on form submit Modal should pop up and ask user Job has created do you want to send this information to client if user click yes then sms and email with above details should be send to client if user says no it should return to edit mode and the created job code should be flushed
How to achieve this in Yii2?
Ideal Situation:
have the modal in your layout file.
yii\bootstrap\Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'modal',
'size' => 'modal-lg',
'closeButton' => [
'id'=>'close-button',
'class'=>'close',
'data-dismiss' =>'modal',
],
//keeps from closing modal with esc key or by clicking out of the modal.
// user must click cancel or X to close
'clientOptions' => ['backdrop' => false, 'keyboard' => true]
]);
echo "<div id='modalContent'><div style='text-align:center'>"
. Html::img('#web/img/radio.gif')
. "</div></div>";
yii\bootstrap\Modal::end();
Add have a js file - with js code to load modal -
$(function() {
$(document).on('click', '.showModalButton', function() {
if ($('#modal').hasClass('in')) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
}
});
});
Include the js file in your application. assets/AppAsset.php :
public $js = ['js/ajax-modal-popup.js'];
Add the the css class: 'showModalButton' to all buttons that content in the modal.
...
'class'=>'btn showModalButton',
...
Modify you controller action to render content via ajax if request was done via ajax:
if(Yii::$app->request->isAjax) {
return $this->renderAjax('your-view-file', [
'model' => $model,
]);
}
Change Modal id from jobPop to modal.
e.g.
<?php
Modal::begin([
'header'=>'<h4>Job Created</h4>',
'id'=>'modal',
'size'=>'modal-lg',
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
Bootsrap 4: https://www.yiiframework.com/extension/yiisoft/yii2-bootstrap4/doc/api/2.0/yii-bootstrap4-modal
Modal::begin([
'title' => 'Hello world',
'toggleButton' => ['label' => 'click me'],
]);
echo 'Say hello...';
Modal::end();

issue Drupal 7 submit button not work with theming

Hello I have an issue when i will redesign the display of form in Drupal 7.
The submit boutton not work only with a theme and not if it's displayed simply.
I try to check some information releated about this but nothing can help me at this time.
I hope there are enough information to help me
My form php:
$form=array();
$form['myform']=array(
'#type'=>'fieldset',
'#title' => 'Enter the NA'
);
$def_na='';
if (isset($param['NA'])) {$def_na=$param['NA'];}
$form['NA'] = array(
'#type' => 'textfield',
'#title' => t('Called number (NA):'),
'#default_value' => $def_na,
'#maxlength' => 10,
'#minlength' => 4,
'#required' => TRUE,
//'#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
);
$def_period='Daily';
if (isset($param['PERIOD'])) {$def_period=$param['PERIOD'];}
$form['period'] = array(
'#type' => 'select',
'#title' => t('Period'),
'#options' => array(
'Daily'=>'Daily',
'Weekly'=>'Weekly',
'Monthly'=>'Monthly'
),
'#default_value' => $def_period,
//'#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Refresh data'));
return $form;
my tpl.php page:
<table>
<tr>
<td>
<?php print drupal_render($form['NA']); ?>
</td>
<td>
<?php print drupal_render($form['period']); ?>
</td>
</tr>
<tr>
<td>
<?php print drupal_render($form['submit']); ?>
</td>
</tr>
</table>
<?php print drupal_render_children($form);?>
thanks for your help

How to handle multiple forms in the same view?

I have a default form for my specific view.
Through an element I (dinamically) include another view (using view extension) in order to provide an upload form.
My problem is that the second form seems to submit the first one.
Default form
<div class="content-box-content">
<?php
echo $this->Form->create("WebSubject", array(
'inputDefaults' => array(
'error' => array(
'attributes' => array(
'wrap' => 'span',
'class' => 'input-notification error png_bg'
)
)
)
));
?>
<?=$this->Form->input('id', array('type' => 'hidden'))?>
<?=$this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire'))?>
<?=$this->Form->input('description', array('type' => 'textarea', 'label' => 'Descriere', 'id' => 'description'))?>
<?=$this->Form->input('description_long', array('type' => 'textarea', 'label' => 'Continut', 'id' => 'description_long'))?>
<?=$this->Form->submit('Salveaza', array('class' => "button"))?>
</div>
This way I include the element
<div class="tab-content default-tab" id="fotoUploadTab">
<?php
echo $this->element('file_upload_form', array(
'view' => 'upload_admin',
'webFileType' => 'image',
'redirect' => $SHT['here']
)
);
?>
<div class="tab-content default-tab">
Lista imagini
</div>
</div>
Element code
<?php
$view = (isset($view)) ? $view : "upload_admin";
$webFileType = (isset($webFileType)) ? $webFileType : "image";
$redirect = (isset($redirect)) ? $redirect : "/";
?>
<?php
$this->extend("/WebFiles/".$view);
?>
Extended View code
<div class="tab-content default-tab">
<?php echo $this->Form->create("WebFile", array('action' => '/', 'type' => 'file')); ?>
<input type="hidden" name="redirect" value="" />
<?php echo $this->Form->input('entity_id', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('entity_table_name', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('type', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire')); ?>
<?php echo $this->Form->input('description', array('class' => "text-input small-input", 'label' => 'Descriere')); ?>
<?php echo $this->Form->submit('Upload', array('class' => 'button')); ?>
</div>
As seen in the last snippet, I tried to force the last form by providing an action url, but on submiting it, it sends data as the first one does.
How should I handle this ?
Thank you!
If you just want to have both forms, the one from parent and the other from the child view/element make sure you call $this->Form->end() in both templates and that you are not nesting a form inside the other. Probably, in your case, just by adding end() to both forms will solve your issue.
As a side note, you cannot have a parent view opening a Form with $this->Form->create() and inject fields into it using the child view, basically because you need create() to be called before any input is rendered and parent views are rendered after the child is executed.

Zend Framework: help needed with Form Decorators

I'm new with developing in Zend Framework. I did some research about form decorators but i want some specific stuff.
This is what i want:
<table>
<tr>
<td colspan="2">
<ul class="errors">
<li>error</li>
</ul>
</td>
</tr>
<tr>
<td>Label :</td>
<td>input field</td>
</tr>
<tr>
<td></td>
<td>Submit Button</td>
</tr>
</table>
What i've got is:
$this->setElementDecorators(array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$submit->setDecorators(array('ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array(array('emptyrow' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element', 'placement' => 'PREPEND')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$this->setDecorators(array(
'FormElements',
'Errors'
array('HtmlTag', array('tag' => 'table')),
'Form'
));
but it comes with an htmlspecialchar warning, and the ul is empty.
is there any possibility to fix this?
Validation errors are tied to individual inputs rather than to the form, so I believe you may have a hard time getting this to work using decorators only.
I would simply render the individual form elements, along with the validation errors, separately in the view script. You'd need to prepare the errors for display yourself and get rid of the decorators altogether, sticking only with the ViewHelper. Then you can do this:
<form method="post">
<table>
<tr>
<td colspan="2"><?php echo $this->errors; ?></td>
</tr>
<tr>
<td><?php echo $this->form->foo->getLabel(); ?></td>
<td><?php echo $this->form->foo; ?></dt>
</tr>
</table>
</form>