CLinkColumn and filter - php

I use framework YII. I will do link for e-mail in my list from GRID. I added this:
array(
'class'=>'CLinkColumn',
'header'=>'e-mail',
'labelExpression'=>'$data->email',
'urlExpression'=>'"mailto:".$data->email',
),
this working ok, but now i dont hava column filter. CLinkColumns doesnt has method filter. How can i make link mailto: and use filter for this?

You could also try something like this:
array(
'name' => 'email',
'header' => 'e-mail',
'type' => 'raw',
'value' => 'CHtml::link($data->email,"mailto:".$data->email)'
),

You can't use a filter with CLinkColumn.
The Yii developers discussed adding 'name' to CLinkColumn here: https://github.com/yiisoft/yii/pull/970
They decided against it:
... there is no need to "complicate" [CLinkColumn] further as that would be just a duplication of code or "hacks" to solve issues...
samdark says:
CLinkColumn will be there for simple usage only . If you need more options, consider using value.
This is their recommended alternative:
array(
'name' => 'field_name',
'type' => 'raw',
'value' => 'CHtml::link($data->field_name,$data->field_name)'
),

give it a shot like this --
array(
'class'=>'CLinkColumn',
'header'=>'e-mail',
'labelExpression'=>'$data["email"]',
'urlExpression'=>'"mailto:".$data["email"]',
),

Related

Codeigniter form validation for big form (28 fields)

I have form consists of 28 fields (client requirement).
I am using Codeigniter framework. I have to type 28 lines of code for form validation.
Is there anything else I can do like creating helper for form validation.
Any help would be appreciated.
Thanks
There is no standard here or a right way to do it and your best option is to create a validation rule for every single input of them in your validation array and maybe you can make a check to categorize some of them like "fname, lname, ..." those have the same validations, but that won't save you anything just added overhead.
But maybe your best shot is to create a function in your base_controller like this:
function set_validation_rules()
{
$this->load->library('form_validation');
$config = array(
array(
'field' => 'firstname',
'label' => $this->lang->line($line.'firstname'),
'rules' => 'trim|required|alpha|min_length[3]|max_length[15]'
),
array(
'field' => 'lastname',
'label' => $this->lang->line($line.'lastname'),
'rules' => 'trim|required|alpha|min_length[3]|max_length[15]'
),
array(
'field' => 'password',
'label' => $this->lang->line($line.'password'),
'rules' => 'trim|required|min_length['.$min.']|max_length['.$max.']'
),
array(
'field' => 'passconf',
'label' => $this->lang->line($line.'password_confirm'),
'rules' => 'trim|matches[password]'
)
);
$this->form_validation->set_rules($config);
}
or create a helper as you suggested, but the most important step is to make a convention for yourself for var/inputs naming and make it a habit so inputs from different view have the same names and pass all inputs to this function for validation after modifying by adding a switch cases to it so every firstname has its own rules and every password has its own and so on, hope you got the idea.

PHP Zend 2 Framework show Textarea

I'm creating a form using Zend2 framework, and can't figure out why a simple Textarea is not showing up on the view (below you can see my code). I've tried the type Text and it shows a standard single lined text field, but got luck with Textarea. I've also tried a non existing type, and zend throws an exception, so it seems Textarea type actually exists, and I must be missing a mandatory param or something like that. Could anyone point me in the right direction?
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
)
));
SOLVED
My bad, it looks there was an intermediate layer in the project ignoring all the Textarea fields.
I just check you code and found 2 things missing first
use Zend\Form\Element;
use Zend\Form\Form;
Which I think you have used in you file.
Another mistake was you were missing comma in the code. use this below code.
$this->add(array(
'type' => 'Zend\Form\Element\Textarea',
'name' => 'pincodes',
'options' => array(
'label' => 'Pincodes (uno por línea)',
),
'attributes' => array(
'rows' => '10',
'cols' => '75',
),
));
Good luck
Try changing your 'rows' and 'cols' value from a string to integer (remove single quotes).
'attributes' = > array(
'rows' => 10,
'cols' => 75,
);

Jquery attr doesnt work on Yii

I'm trying to change the element value using Jquery but it's not working...
This is my widget where I have my element 'tag' which i want to change it to textField on edit...
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider->searchbyID($invoice_id),
'template' => '{items}{buttonCreateRow}{pager} ',
'id' => 'InvoiceLine-grid',
'rowTemplate' => $row_template,
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'InvoiceLine_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
'onclick'=>'editline(this)',
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]stentysproductref',
'tag' => 'laabel',
'tagHtmlOptions' => array(
'style'=>'background-color:#FFF;border-color:#FFF',
'onkeyup'=>'stentysref(this)',
'readonly'=>true
)
),
My Jquery is,
(as you can see the removeAttr works but attr doesn't)
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").attr("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeAttr("readonly");
}
Use .prop() and removeProp() which is added in jQuery 1.6, as the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior.
function editline(obj){
$("#InvoiceLine_1_"+row+"_stentysproductref").prop("tag","textField");
$("#InvoiceLine_1_"+row+"_stentysproductref").removeProp("readonly");
}
API Doc for .prop()
If you are using EditableGrid widget without pointing AR model, then the row id looks like
$('#_1_'+row+'stentysproductref').
I'll take it into consideration for the future updates. Thank you.

Using CakeDC's search plugin to search data with multi-select field

I am trying to implement a search with CakeDC's Search plugin. In this search I have a field which has 'multiple' => 'checkbox' is set. This field allows user to select multiple cities so that they can filter results according to city/cities. What I did in favour to this, I simply specified the 'type' => 'IN' for that field in Searchable Model's $filterArgs. But noting happened it just responded with all result no searching/filtration happened. To get the clear picture of what I have implemented here are the code snippets:
Model.php
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
'city' => array(
'type' => 'in',
'field' => 'Model.city'
));
search_form.ctp
echo $this->Form->create('Model', array('url' => array('controller' => 'models', 'action' => 'search')));
echo $this->Form->input('city', array(
'multiple' => 'checkbox',
'options' => array(
'city1' => 'city1',
'city2' => 'city2',
'cityn' => 'cityn')
));
echo $this->Form->end('search');
ModelsController.php
public function search() {
$this->layout = 'front_common';
$this->Prg->commonProcess();
$this->Paginator->settings = array(
'conditions' => $this->Model->parseCriteria($this->Prg->parsedParams()),
'limit' => 10
);
$this->set('Data', $this->Paginator->paginate());
}
also once I tried to use a beforeFilter() in ModelsController to implode the city array() with (,) to be used with IN but same all results. I want to ask if there is any other plugin to do this or any hack to do this with cakeDC's search plugin. Please help.
This should work fine, assuming you are passing in the arg to parseCriteria() as a simple array of values.
public $filterArgs = array(
array(
'name' => 'city',
'type' => 'value',
'field' => 'Model.city'
)
);
And you should be able to pass city:houston|dallas|austin in the URL
It should parse that into an array of args => [city => [houston, dallas, austin]]
And parseCriteria() will translate that into the following conditions fragment: [Model.city => [houston, dallas, austin]]
And CakePHP natively translates that into a SQL where fragment: IN(houston, dallas, austin)
Use DebugKit and monitor your SQL... you can debug() at any step of the process, you should get these values.
Here's the full docs on the Search plugin:
https://github.com/CakeDC/search/tree/master/Docs/Documentation
(I use it heavily, and I love how it lets me organize all search filters)

codeigniter how can I get access to config/form_validation.php data?

I have duplicated data across my config/form_validation.php and my controller.
the field and label from form_validation is the same that I specify in my controller for the id, name and placeholder
Do I have to extract that data to yet a third location and reference it in both of these?
application/config/form_validation.php
$config = array(
'register' => array(
array(
'field' => 'register_username',
'label' => 'Username',
'rules' => 'trim|required|exact_length[5]'
),
.....
application/controllers/mycontroller.php
$this->viewdata['register_username'] = array(
'id' => 'register_username',
'name' => 'register_username',
'type' => 'text',
'placeholder' => 'Username'
);
...
I'm not sure why you have your data duplicated in the controller itself. You might find it easier to use Jamie Rumbelow's model/schema libraries mashup.
This will clean up your model/application structure as a whole. The model extension library itself allows for the automation of CRUD methods.

Categories