How to remove controller name in CakePHP Form - php

My code:
echo $this->Form->create('Usps', array(
'inputDefaults' => array(
'label' => false,
'div' => false
),
'id' => 'form-validate',
'class' => 'form-horizontal',
'novalidate' => 'novalidate',
'url' => array('controller'=>'frondends','action' => 'tariffplan')
));
This produces www.example.com/frontends/tariffplan
I want to see : www.example.com/tariffplan
I changed url as follows:
'url' => array('action' => 'tariffplan')
but this produces :
www.example.com/usps/tariffplan
I searched google but no luck. Any help will be appreciated

Try this:
'url' => array('controller' => '/', 'action' => 'tariffplan')

Related

duplicate upload view in XUpload Yii

I need two upload file with two upload view in one page with extension XUpload in Yii, but render first upload view.
$model = new MMediaUploadForm;
$url = aUrl('/project/media/upload', array('projectId' => $this->project->id));
$this->widget('uniprogy.extensions.xupload.XUpload', array(
'url' => $url,
'model' => $model,
'attribute' => 'file',
'downloadView' => $this->render('download', array('listWorkletId' => $this->getDOMId()), true),
'uploadView' => $this->render('upload', array(), true),
'uploadTemplate' => '#template-upload',
'formView' => $this->render('form', array(
'url' => $url,
'model' => $model,
'attribute' => 'file',
'htmlOptions' => array(
'id' => get_class($model) . "-form",
'enctype' => 'multipart/form-data',
),
), true),
));
$url1 = aUrl('/project/media/upload1', array('projectId' => $this->project->id));
$this->widget('uniprogy.extensions.xupload.XUpload', array(
'url' => $url1,
'model' => $model,
'attribute' => 'file',
'downloadView' => $this->render('download', array('listWorkletId' => $this->getDOMId()), true),
'uploadView' => $this->render('upload1', array(), true),
'uploadTemplate' => '#template-upload1',
'formView' => $this->render('form1', array(
'url' => $url1,
'model' => $model,
'attribute' => 'file',
'htmlOptions' => array(
'id' => get_class($model) . "-form",
'enctype' => 'multipart/form-data',
),
), true),
));
i have two text/x-tmpl with two id but just render first upload view!
help me plz thanks!

Condition inside route definition

I just started to use ZendFramework 2. I defined a route in my module.config.php and I want to use the $this->url in my view to generate the url.
module.config.php
'settings-users-list' => array(
'type' => 'Zend\Mvc\Router\Http\Regex',
'options' => array(
'regex' => '/settings((/role/(?<role>[a-zA-Z]+))|)((/search/(?<search>[a-zA-Z0-9_-]+))|)((/page/(?<page>[0-9]+))|)((/date/(?<date>asc|desc))|)((/log/(?<log>asc|desc))|)',
'defaults' => array(
'controller' => 'Admin\Controller\Settings',
'action' => 'index',
),
'spec' => '/settings/role/%role%/search/%search%/page/%page%/date/%date%/log/%log%',
),
),
In my view
echo $this->url('admin/settings-users-list',$link_params,array('force_canonical' => true));
where
$link_params = array(
'controller' => 'settings',
'action' => 'index',
'role' => 'admin',
'search' => '',
'page' => '',
'date' => '',
'log' => '',
);
My problem is that when a part of my parameters are empty the generated url is not the desired one. In this case the the generated url is:
www.mysite.com/admin/settings/role/admin/search//page//date//log/
Is there a way to not display search, page, date, log if this parameter is not set. Maybe is there a way to put a condition in spec field of settings-users-list route in module.config.php.
In your case I would suggest to not add the search params like search, page, date and log to your route at all. Those are query params and for this ZF2 url helper has a special query key in options. You can also find this in the paragraph Query String Arguments in the ZF2 url view helper documentation. In your case you can use it like this:
$params = array(
'controller' => 'settings',
'action' => 'index',
'role' => 'admin'
);
$query = array(
'search' => '',
'page' => '',
'date' => '',
'log' => ''
);
$options = array(
'force_canonical' => true,
'query' => $query
);
echo $this->url('admin/settings-users-list', $params, $options);
I would also suggest to simplify your router. It will be much more readable without a regex:
'settings' => array(
'type' => 'Literal',
'options' => array(
'route' => '/settings'
)
'may_terminate' => false,
'child_routes' => array(
'role' => array(
'type' => 'Segment',
'options' => array(
'route' => '/role/:role'
'constraints' => array(
'role' => '[a-zA-Z]*'
),
'defaults' => array(
'controller' => 'Application\Controller\Settings',
'action' => 'index',
)
)
)
)
),
Then you can do like this:
echo $this->url('settings/role', $params, $options);

Ajax Request is Not Working After CGridView Update

I Want to open a CJuiModel by Clicking on CGridView CButtonColumn view Button as my CGridView and CJuiModel is as:-
<?php
$dataProvider = new CArrayDataProvider($model->exhibitorLocation, array(
'keys' => array('productId'),
));
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'id' => 'exhibitor-location-grid',
'summaryText' => false,
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
),
'columns' => array(
array(
'header' => 'S No.',
'value' => '++$row',
),
array(
'header' => 'Hall No',
'value' => '$data->location->hallNo',
),
array(
'header' => 'Stand No',
'value' => '$data->standNo',
),
array(
'class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{view}{delete}',
'buttons' => array(
'view' => array(
'imageUrl' => $this->module->assetsUrl . "/images/info_icon.png",
'options' => array('class' => 'exb-location'),
'url' => 'Yii::app()->createUrl("admin/venuemap/viewExbLocation", array("exbLocId"=>$data->primaryKey))',
),
'delete' => array(
'imageUrl' => $this->module->assetsUrl . "/images/delete_icon.png",
'url' => 'Yii::app()->createUrl("admin/venuemap/deleteExbLocation", array("exbLocId"=>$data->primaryKey))',
),
),
'htmlOptions' => array(
'style' => 'width:100px;float:center'
)
),
),
'rowCssClassExpression' => '($row%2 ? "visit2" : "visit1")',
'itemsCssClass' => 'visitor_list',
'htmlOptions' => array(
)
));
?>
<div class="name_field">Hall No<span>*</span></div>
<?php echo CHtml::dropDownList('hall-no', '', CHtml::listData(Venuemap::model()->findAll(), 'locationId', 'hallNo'), array('class' => 'name_input2', 'id' => 'hall-no')); ?>
<div class="name_field">Stand No</div>
<?php echo CHtml::textField('Stand No', '', array('class' => 'name_input', 'id' => 'stand-no')); ?>
<?php
echo CHtml::ajaxLink("Add Location", Yii::app()->createUrl('admin/venuemap/addExbLocation'), array(
'type' => 'post',
'data' => array(
'exhibitorId' => $model->exhibitorId,
'standNo' => 'js: $("#stand-no").val()',
'locationId' => 'js: $("#hall-no").val()'
),
'success' => 'function(html){ $.fn.yiiGridView.update("exhibitor-location-grid"); }'
), array('class' => 'search_btn'));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'location-dialog',
'options' => array(
'title' => 'View Location',
'autoOpen' => false,
'modal' => true,
'width' => 'auto',
'height' => 'auto',
'resizable' => false
),
));
$this->endWidget();
?>
<?php
Yii::app()->clientScript->registerScript('view-location-ajax', "
$('.exb-location').click(function(){
url=$(this).attr('href');
$.ajax({
type: 'post',
url: url,
success: function(result){
$('#location-dialog').html(result).dialog('open');
$('#draggable').draggable();
return false;
}
});
return false;
});
");
?>
View Button is working fine and open a CJuiModel on click but when I add a new Location in CGridView .
On Clicking on view button my CJuiModel is not opening and page is redirecting to Url.Why my jquery is getting failed on updating CGridView. Help..
Change ajax call using JQuery 'on' instead direct event binding:
This:
...
$('.exb-location').click(function(){
...
Change for:
...
$('.exb-location').on('click', '.exb-location', function(){
...
Html Elements are destroyed and regenerated after CGridview refresh. Direct JQuery events only work with existing elements before DOM load. When they are removed, or new elements are added later, direct events don't work.

ZF2 Redirect to route with controller action and get param

So I'm trying to redirect my code to another action within a controller http://localhost/salesorder/view?id=5509c273f948e7cf068b456a this view action is working fine. But every time the redirect code runs it redirects me to http://localhost/salesorder?id=5509c273f948e7cf068b456a
I am now clueless what is did I do wrong.
$params = ['controller' => 'SalesOrder',
'action' => 'view',
];
$options = ['query' => ['id' => (string) $orderId]];
return $this->redirect()->toRoute('Salesorder', $params, $options);
My moduleconfig looks like this
'Salesorder' => array(
'type' => 'Literal',
'options' => array(
'route' => '/salesorder',
'defaults' => array(
'__NAMESPACE__' => 'Backend\Controller',
'controller' => 'SalesOrder',
'action' => 'new',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:action]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'action' => 'new'
),
),
),
),
),
Excuse me that I cannot put a comment since I have not enough reputation, but this may lead you to a solution:
First of all fix the toroute function call to this:
return $this->redirect()->toRoute('Salesorder', array('id'=> (string) $orderId));
Then fix the route specification to this:
'Salesorder' => array(
'type' => 'segment',
'options' => array(
'route' => '/MODULE_NAME/SalesOrder/new/:id[/]',
'constraints' => array(
'id' => '[a-zA-Z0-9_-]*'
),
'defaults' => array(
'controller' => 'MODULE\Controller\SalesOrder',
'action' => 'new',
),
),
),

PHP attachment in write form

I need to edit the following form so it will have attach file function:
function _getWriteForm()
{
$aForm = array(
'form_attrs' => array(
'name' => 'WallPostText',
'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/',
'method' => 'post',
'enctype' => 'multipart/form-data',
'target' => 'WallPostIframe',
'onsubmit' => 'javascript:return ' . $this->_sJsPostObject . '.postSubmit(this);'
),
'inputs' => array(
'content' => array(
'type' => 'textarea',
'name' => 'content',
'caption' => '',
'colspan' => true
),
'submit' => array(
'type' => 'submit',
'name' => 'submit',
'value' => _t('_wall_post'),
'colspan' => true
)
),
);
I wanted to edit HTML file first, but the only HTML code for this is:
<!-- Post Text -->
<div class="wall-ptype-cnt wall_text">__post_wall_text__</div>
Can someone please help me with editing array to allow file attachment?
Thank you.
You should try something like this:
function _getWriteForm()
{
$aForm = array(
'form_attrs' => array(
'name' => 'WallPostText',
'action' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'post/',
'method' => 'post',
'enctype' => 'multipart/form-data',
'target' => 'WallPostIframe',
'onsubmit' => 'javascript:return ' . $this->_sJsPostObject . '.postSubmit(this);'
),
'inputs' => array(
'content' => array(
'type' => 'textarea',
'name' => 'content',
'caption' => '',
'colspan' => true
),
'file' => array(
'type' => 'file',
'name' => 'upload_file',
'caption' => 'Upload',
'colspan' => true
),
'file_two' => array( //I added a second input file
'type' => 'file',
'name' => 'upload_file_two',
'caption' => 'Upload',
'colspan' => true
),
'submit' => array(
'type' => 'submit',
'name' => 'submit',
'value' => _t('_wall_post'),
'colspan' => true
)
),
);
I hope it helps.
Saludos ;)

Categories