Adding class to form_dropdown in CodeIgniter - codeigniter

How do I add a class to a form_dropdown in CodeIgniter if I also have a Javascript attached. Here is my code:
$language = array(
'select' => 'Select Language',
'chinese' => '中文',
'english' => 'English',
'french' => 'Français',
'german' => 'Deutsch',
'italian' => 'Italiano',
'japanese' => '日本',
'korean' => '한국어',
'polish' => 'Polska',
'portuguese' => 'Português',
'russian' => 'Росс&#1048Ю',
'spanish' => 'Español'
);
$js = 'onChange="this.form.submit()"';
echo form_dropdown('language', $language, 'select', $js);

Add the class to the $js variable;
$js = 'onChange="this.form.submit()" class="myClass"';

Related

Site refresh time is long in laravel?

Hello and do not be tired!!
My admin panel pages are hard to load...It takes 15 seconds for the pages to load!!
The problem is with my routes!!!
Because when I define the path as follows, the pages load quickly :
Route::get('users/index', function () {
return view('admin.index');
});
But the route I have defined is as follows :
Route::group(['middleware' => ['auth' , 'InfoFolder' , 'verified' , 'Roles'] , 'prefix' => 'users/'] , function(){
Route::get('{url}', [UrlController::class , 'urlpanel'])->name('users_url');
});
And the control I have defined :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UrlController extends Controller
{
//
public function urlpanel($url ){
$admin = "admin";
$pages = "admin.pages";
$charts = "admin.pages.charts";
$examples = "admin.pages.examples";
$forms = "admin.pages.forms";
$mailbox = "admin.pages.mailbox";
$tables = "admin.pages.tables";
$UI = "admin.pages.UI";
$link_panel = [
'index' => "$admin.index",
'list_users' => "$admin.list_users",
'index3' => "$admin.index3",
'calendar' => "$pages.calendar",
'widgets' => "$pages.widgets",
'chartjs' => "$charts.chartjs",
'flot' => "$charts.flot",
'inline' => "$charts.inline",
'404' => "$examples.404",
'500' => "$examples.500",
'blank' => "$examples.blank",
'invoice-print' => "$examples.invoice-print",
'invoice' => "$examples.invoice",
'lockscreen' => "$examples.lockscreen",
'login' => "$examples.login",
'profile' => "$examples.profile",
'register' => "$examples.register",
'product_add' => "$forms.product_add",
'editors' => "$forms.editors",
'general' => "$forms.general",
'compose' => "$mailbox.compose",
'mailbox' => "$mailbox.mailbox",
'read-mail' => "$mailbox.read-mail",
'data' => "$tables.data",
'simple' => "$tables.simple",
'buttons' => "$UI.buttons",
'general' => "$UI.general",
'icons' => "$UI.icons",
'sliders' => "$UI.sliders",
];
if(!in_array($link_panel[$url] , $link_panel)){
return abort(404);
}
return view($link_panel[$url]);
}
}
How can I increase the loading speed of my website?
The project has been uploaded to Localhost
:)
Try to check the middlewares you are using. Maybe in one of the middlewares there is some time consuming action.

Preview image in ACF gutenberg block

Is it possible to add an image to the gutenber block preview when using ACF to register the block ?
Here's the code to register the block:
acf_register_block(array(
'name' => 'bk-raisons',
'title' => __('Les raisons', 'diezel'),
'description' => __('Les raisons', 'diezel'),
'render_callback' => 'my_acf_block_render_callback',
'category' => 'spira-custom',
'icon' => 'align-wide',
'keywords' => array('bk-raisons'),
));
The preview appears when hovering the block.
Thank you !
I finally found a solution.
I don't know if you use Twig (Timber) or not.
If not check this : https://stackoverflow.com/a/67846162/6696150
For my part with Timber
When you declared your block add example attributes :
$img_quadruple = array(
'name' => 'img-quadruple',
'title' => __('Quatre images'),
'title_for_render' => 'img-quadruple',
'description' => __(''),
'render_callback' => 'ccn_acf_block_render_callback',
'category' => 'imgs',
'icon' => '',
'mode' => 'edit',
'keywords' => array( 'quatre images' ),
'example' => array(
'attributes' => array(
'mode' => 'preview',
'data' => array(
'preview_image_help' => get_template_directory_uri().'/assets/img/preview/preview_img_quadruple.jpg',
),
)
)
);
And when your declared your callback :
function ccn_acf_block_render_callback( $block, $content = '', $is_preview = false ) {
$context = Timber::context();
// Store block values.
$context['block'] = $block;
// Store field values.
$context['fields'] = get_fields();
// back-end previews
if ( $is_preview && ! empty( $block['data'] ) ) {
echo '<img src="'. $block['data']['preview_image_help'] .'" style="width:100%; height:auto;">';
return;
} elseif ( $is_preview ) {
echo 'Other condition';
return;
}
// Store $is_preview value.
$context['is_preview'] = $is_preview;
// Render the block.
Timber::render('gutenberg/gut_' . strtolower($block['title_for_render']) . '.twig', $context );
}

drupal custom views filter

First time on stackoverflow so , i will try to be as clear as possible.
I'm using drupal 7 and views 3.
I needed to create a custom views filter that handle dates range. So i looked at example and tried to mimic the behavior and i get some trouble.
It seems that when i extend my own class from views_handler_filter , the query method is never invoked BUT if i extend my class from let's say views_handler_filter_string, it works oO...
I must forget something but i'm stuck here ...
Here is my code, if someone can take a look and advise me about what happend , i would be very grateful.
Thanks everyone !
Here is my .views.inc file :
<?php
class v3d_date_custom_filter extends views_handler_filter {
var $always_multiple = TRUE;
function value_form(&$form, &$form_state) {
//parent::value_form($form, $form_state);
$form['value']['v3d_date']['period'] = array(
'#type' => 'select',
'#title' => 'Period',
'#options' => array(
'7_days' => 'Last 7 days',
'yesterday' => 'Yesterday',
'today' => 'Today',
'custom' => 'Custom dates'),
'#default_value' => 'custom',
'#attributes' => array("onclick" => "period_click(this);"),
);
$form['value']['v3d_date']['start_date'] = array(
'#type' => 'date_popup',
'#date_format' => 'Y-m-d',
'#title' => 'Start date',
'#size' => 30);
$form['value']['v3d_date']['end_date'] = array(
'#type' => date_popup',
'#title' => 'End date',
'#date_format' => 'Y-m-d',
'#size' => 30);
}
function exposed_validate(&$form, &$form_state) {
if(is_null($form_state['values']['start_date']) &&
is_null($form_state['values']['start_date'])) {
return TRUE;
}
/*
* If we get array for start_date or end_date
* errors occured, but the date module will handle it.
*/
if(!is_string($form_state['values']['start_date']) ||
!is_string($form_state['values']['end_date'])) {
return TRUE;
}
/* Get day, month and year from start_date string */
if(!preg_match('/(\d+)-(\d+)-(\d+)/',
$form_state['values']['start_date'],
$start_date
)) {
return TRUE; }
/* Get day, month and year from end_date string */
if(!preg_match('/(\d+)-(\d+)-(\d+)/',
$form_state['values']['end_date'],
$end_date
)) {
return TRUE; }
/* Create timestamps and compare */
$start_date = mktime(0,0,0,$start_date[1],$start_date[2],$start_date[3]);
$end_date = mktime(0,0,0,$end_date[1],$end_date[2],$end_date[3]);
if($start_date >= $end_date) {
form_set_error('start_date','Start date must be anterior to end date.');
}
}
function query() {
die('fdsfds');
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
dsm($this);
}
}
?>
And my .module file
<?php
function custom_filters_views_api() {
return array(
'api'=>3,
'path' => drupal_get_path('module','custom_filters') . '/views',
);
}
?>
And part of my views_data that use my custom filter :
<?php
function voice_views_data() {
$data['v_tp_voice']['date_utc_agent'] = array(
'title' => t('date_utc_agent'),
'help' => 'date_utc_agent',
'field' => array('handler' => 'views_handler_field'),
'filter' => array('handler' => 'v3d_date_custom_filter'),
'sort' => array('handler' => 'views_handler_sort')
);
I am working on this same problem. My setup looks very much like yours, though I do call parent::value_form($form, $form_state) in my value_form function.
I found that in the value_form function, I had to have something like
$form['value'] = array(
'#type' => 'checkbox',
'#title' => "Filter by Date",
'#default_value' => $this->value,
);
in order to have my query() function called. Doing something like $form['value']['before'] = array( ...
didn't work.

magento - add customer name to order grid in magento 1.7.0.2

I'm trying to add a new column for Customer Name in the Sales Order Grid located here:
App/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
I want add Customer Name like Name in Manage Customers.
I have added the following code:
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
/*junpeng add start*/
$collection->getSelect()
->join(
'customer_entity',
'main_table.customer_id = customer_entity.entity_id', array('email' => 'email'));
$collection->getSelect()->join(
'customer_entity_varchar',
'main_table.entity_id = customer_entity_varchar.entity_id', array('name' => 'value')
);
/*junpeng add end*/
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => Mage::helper('sales')->__('Customer Name'),
'index' => 'name',
));
$this->addColumn('email', array(
'header' => Mage::helper('Sales')->__('Customer Email'),
'index' => 'email',
'type' => 'text',
));
}
Customer Email is OK,but add Customer Name does not work it!
Can someone please help me solve this problem?
You can't get customer name in just one line code join. Firstname and Lastname are different attributes and you will need to join them with your original collection and then concatenate them to display as Fullname.
So basically, Replace
$collection->getSelect()->join(
'customer_entity_varchar',
'main_table.entity_id = customer_entity_varchar.entity_id', array('name' => 'value')
);
with this code
$fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');
$collection->getSelect()
->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
->where('ce1.attribute_id='.$fn->getAttributeId())
->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
->where('ce2.attribute_id='.$ln->getAttributeId())
->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS customer_name"));
And replace your addColumn('name', code in _prepareColumns method where you are getting the customer name, with this:
$this->addColumn('customer_name', array(
'header' => Mage::helper('sales')->__('Customer Name'),
'index' => 'customer_name',
'filter_name' => 'customer_name'
));
There is a free magento extension for this:
http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html
It's currently alpha, but I have tested it and it works perfectly on 1.6 and 1.7!
I inspire my answer from Kalpesh
so you should replace this code
$collection->getSelect()->join(
'customer_entity_varchar',
'main_table.entity_id = customer_entity_varchar.entity_id', array('name' => 'value')
);
with these lines
$customerTable = Mage::getResourceSingleton('customer/customer')->getEntityTable();
$firstnameAttribute=Mage::getResourceSingleton('customer/customer')->getAttribute('firstname');
$firstnameAttributeTable = $firstnameAttribute->getBackend()->getTable();
$lastnameAttribute=Mage::getResourceSingleton('customer/customer')->getAttribute('lastname');
$lastnameAttributeTable = $lastnameAttribute->getBackend()->getTable();
$collection->getSelect()
->join( array('customer_varchar1'=>$firstnameAttributeTable),'main_table.customer_id =customer_varchar1.entity_id and customer_varchar1.attribute_id='.$firstnameAttribute->getId(),
array('customer_varchar1.value'))
->join( array('customer_varchar2'=>$lastnameAttributeTable),'main_table.customer_id =customer_varchar2.entity_id and customer_varchar2.attribute_id='.$lastnameAttribute->getId(),
array('customer name'=>'CONCAT(customer_varchar2.value ," " ,customer_varchar1.value)'));

How to put drop down list into array using codeigniter

I use the ion auth for codeigniter and it works great except that I don't know how to code drop down list the same way as the text field.
If you want to display a text field under view you have to issue this:
<?php echo form_input($first_name);?>
And this is the code under controller:
$this->data['first_name'] = array(
'name' => 'first_name',
'id' => 'first_name',
'type' => 'text',
'size' => 32,
'maxlength' => 32,
'value' => $this->form_validation->set_value('first_name'),
);
But how can I put the value of my drop down list into an array?
I tried putting this code under view:
<?php
$options = array(
'' => 'Select',
'Dr' => 'Dr.',
'Mr' => 'Mr.',
'Mrs' => 'Mrs.',
'Ms' => 'Ms.',
'Prof' => 'Prof.',
'Mr. & Mrs.' => 'Mr. & Mrs.',
);
echo form_dropdown('title', $options, '$title');
?>
I am thinking that under view I should code it like: echo form_dropdown($title); the same as text field but what is the code under controller?
First in your controller you can do :
$options = array(
'0' => 'Select',
'Dr' => 'Dr.',
'Mr' => 'Mr.',
'Mrs' => 'Mrs.',
'Ms' => 'Ms.',
'Prof' => 'Prof.',
'Mr. & Mrs.' => 'Mr. & Mrs.',
);
$data['options'] = $options
$this->load->view('your_view',$data);
In the View :
echo form_dropdown('title', $options, set_value('title'));
Moreover think you want to retain the value of the dropdown if a form validation error occurs:
you just need to put some validation to retain the values of the dropdown , somethin like:
$this->form_validation->set_rules('title','Titles','alpha');
If not validatted the dropdown will not retain the values in spite of using set_value

Resources