Changing page labels (clistview, cgridview) witout changing pager css (bootstrap) - php

When I set 'pager' in CGridView it change bootstrap look, I try with cssFile to null or false, it doesn't work.
'pager' => array(
'class' => 'CLinkPager',
'firstPageLabel' => '<<',
'prevPageLabel' => 'smthprev',
'nextPageLabel' => 'smthnext',
'lastPageLabel' => '>>',
),

The Bootstrap extension checks if htmlOptions['class'] is set , i.e : isset($htmlOptions['class']), so if we set empty class, then it should work. So add this:
'pager' => array(
// rest of code
'htmlOptions'=>array('class'=>'')
),

Related

YII how to set a custom delete button for ButtonColumn?

I would like to change the custom implementation of the delete button in gridview for buttoncolumn. I want to add a custom icon and a custom css class to the delete button. When i add the option parameter it dose not work any more. So i decided to create a custom link to the delete function but it gives me a 400 error when i click on it.
Any ideas ?
Below code
array(
'header' => __('Manage'),
'class' => 'booster.widgets.TbButtonColumn',
// 'htmlOptions'=>array('style'=>'white-space: nowrap;'),
'template' => '{approve} {details} {erase}',
'htmlOptions' => array('style' => 'white-space: nowrap;'),
'buttons' => array(
'approve' => array(
'label'=>__('Approve'),
'icon'=>'pencil',
// 'options' => array('target' => '_blank'),
'url' => 'Yii::app()->createUrl(\'tours/updateadmin/\'. $data->tour_id)',
'options' => array(
'class' => 'btn btn-small btn-info',
),
),
'details' => array(
'label'=>__('View Details'),
'icon'=>'check',
'url' => 'Yii::app()->createUrl(\'tours/view/\'. $data->tour_id)',
'options' => array(
'class' => 'btn btn-small btn-info',)
// 'options' => array('target' => '_blank'),
// 'url' => 'Yii::app()->createUrl(\'tours/updateadmin/\'. $data->tour_id)',
),
'erase' => array(
'label'=>__('Delete'),
'icon'=>'trash',
'url'=>'CController::createUrl("/tours/delete", array("id"=>$data->tour_id))',
'options' => array(
'class' => 'btn btn-small btn-info',)
),
),
),
What's your 400 error details? I think the problem is your link. Try to remove first / from your link:
'erase' => array(
'label'=>__('Delete'),
'url'=>'Yii::app()->createUrl("tours/delete", array("id"=>$data->tour_id))',
'options' => array(
'class' => 'btn btn-small btn-info'
)
),
),
If the problem did not resolve, you should edit your question and add error details for better helping.
Also, note that CButtonColumn#buttons does not have icon field. Here is a link that shows possible options for CButtonColumn#buttons . So you should remove icon field from all of your buttons.

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.

Define Yii-Booster Extension in Configuration file

Im new to this, I have downloaded Yii-Booster Widgets for use of TBRelationalColumn.
I have downloaded the extensions from yiibooster.clevertech.biz yiibooster-4.0.1.zip file and extracted under
protected/extensions/booster
Configuration
protected/config/local.php and main.php
<?php
Yii::setPathOfAlias('booster', dirname(__FILE__).'/../extensions/booster');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
return array(
'components'=>array(
'db' => array(
),
'mongodb' => array(
'class' => 'EMongoDB',
),
'booster'=>array(
'class'=>'booster.components.Booster',
'coreCss' => true,
'responsiveCss' => true,
'yiiCss' => true,
),
'bootstrap'=>array(
'class'=>'bootstrap.components.bootstrap',
'coreCss' => true,
'responsiveCss' => true,
'yiiCss' => true,
),
'cache'=>array(
'class' => 'CFileCache',
),
),
);
When Im using this widget im getting the grid structure but js is Not Enable
index.php
$this->widget('booster.widgets.TbExtendedGridView', array(
'id' => 'invite-grid',
'type' => 'striped condensed',
'dataProvider' => $arrayDataProvider,
'columns' => array(
'id',
'username',
'email',
array(
'class' => 'booster.widgets.TbRelationalColumn',
'name' => 'test',
'value' => '"grid"',
'url' => $this->createUrl('site/relational'),
'afterAjaxUpdate' => 'js:function(tr,rowid,data){
bootbox.alert("I have afterAjax events too!<br/>This will only happen once for row with id: "+rowid);
}'
),
)
));
When Click on Grid i cannt get the Alert Message. Please anyone help me to resolve this problem
You are not loading it. If you are using boostrap across all pages, preload it from the config,
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Site',
'preload'=>array(
'log',
'bootstrap', //preload bootsrtap
),
Else, you can add it separately for each controller using filter
public function filters()
{
return array(
'accessControl',
array('ext.booster.filters.BootstrapFilter') //load bootstrap
);

How to Disable Button on CButtonColumn Table

I want to disable the update button from CGridView Table. I don't know how to do it. Just disable the update button, not delete the function of update. Anybody know how to do it? Thanks
'columns' => array(
// All your columns here
// ...
array(
'template' => '{view}{delete}',
'class' => 'CButtonColumn',
),
),
It's enough :)
EDIT: above solution removes the button. The following disable it (by removing the link):
'columns' => array(
// All your columns here
// ...
array(
'template' => '{view}{update}{delete}',
'class' => 'CButtonColumn',
'buttons' => array(
'update' => array(
'url' => ''
),
),
),
You have to change the 'template' property of your CButtonColumn.
The default value for 'template' is '{update}{view}{delete}'.
So you have to do this:
array(
'class' => 'CButtonColumn',
'template' => '{view}{delete}',
),

Yii framework new column in database not showing in output of $model->getAttributes() method call?

Yii version 1.1.8
I have added a column to a table in a mysql database,
but the new column is not showing in output of $model->getAttributes() method call
I deleted all files in protected/runtime folder, but still no column
config: 'schemaCachingDuration' => 0, // in seconds. <1 means off
I can add data to the new column directly in the database.
Are there any other things that I can do to debug this?
index.php
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
// remove the following line when in production mode
//debug
defined('YII_DEBUG') or define('YII_DEBUG',true );
//show profiler
defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',false);
require_once($yii);
Yii::createWebApplication($config)->run();
main.php
<?php
return CMap::mergeArray(array(
'timeZone'=>'UTC',
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'catchAllRequest' => null, // null if online, array('site/offline') if offline,
'sourceLanguage' => 'en_ca',
'theme' => 'td',
'charset' => 'UTF-8',
'preload' => array('log'),
'import' => array(
'application.models.*',
'application.components.*',
'application.extensions.*'
),
'modules' => array(
),
// application components
'components' => array(
'format' => array(
),
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true,
'autoRenewCookie' => true,
),
'widgetFactory' => array(
'enableSkin' => true,
),
'urlManager' => array(
),
),
'db' => array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=mydb',
'emulatePrepare' => true,
'initSQLs'=>array("set time_zone='+00:00'"),
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
'enableParamLogging' => true, //show parameter values in log
// 'schemaCachingDuration' => 0, // in seconds. <1 means off
'enableProfiling' => YII_DEBUG_PROFILING, //show sql profile info in log
'nullConversion' => true,
//'initSQLs'=>array('set time_zone="+00:00"')
),
'errorHandler' => array(
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
'filter' => 'CLogFilter',
'enabled' => !YII_DEBUG
),
array(
'class' => 'CPhpMailerLogRoute',
'levels' => 'error',
'emails' => 'neilmcguigan+tderror#gmail.com',
'filter' => 'CLogFilter',
'enabled' => false,
),
array(
'class' => 'CWebLogRoute', // show log messages on web pages
'enabled' => YII_DEBUG,
'filter' => 'CLogFilter',
//'showInFireBug' => false
),
array(
'class' => 'CProfileLogRoute',
'enabled' => YII_DEBUG,
'showInFireBug' => false
)
),
),
'request' => array(
),
'securityManager'=>array(
)
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params' => array(
),
), require(dirname( __FILE__ ) . '/override.php'));
Having just went through this problem -- I found out the new field names need to be in the attributeLabels function in the model
public function attributeLabels()
{
return array(
'id' => 'ID',
'newfield' => 'New Field',
...
Be careful with using the "better still update overwrite your whole model" suggestion if you are like me and have a lot of custom code in your models. As Sankalp Singha suggests, Just copy the "diff" (green part) from using gii and add the part from attributeLabels to your code.
After you have added a new column in your table then just go to Gii and then click on model generator. In that put the name of your table again and then click preview. There would be an option of diff click on that and then copy the highlighted green code and copy paste it in your original modal or better still update overwrite your whole modal. Then check if you are able to get the values inside and are able to get the attributes. This should work.

Categories