by prettyscripts on 2012-02-10 15:13:00 • Leave a comment »
i recently discovered chive from yii's home page, one of my most frequently visited site recently since i'm working on a project based on yii at the moment.
what is chive? from the site:
Chive is a free, open source, web-based database management tool, designed to bring joy to web developers - with easy administration, super fast UI and state of the art web technologies.
i downloaded a copy (v102) and have been using it for a few weeks.
i've been using phpmyadmin for many years to manage databases. i rely on it so much i've forgotten most mysql /sql commands. it provides a nice interface for most of my needs.
please note that this is not going to be thorough comparision. just a simple comparison based on my usage.
both are free, open source and web-based database management tools.
both are installed by uncompressing the downloaded file and copying to selected server directory.
phpmyadmin requires configuration before using it (and requires some understanding of various configurations). chive runs out of the box.
both have similar user interface, but i like the default look for chive. it looks more modern and fresh.
phpmyadmin look dated but can be themed. there are also options to change certain appearances. chive doesn't have such option.
chive can only manipulate databases on the same server at any one time.
phpmyadmin, once configured, can access databases on different servers from the same interface.
chive does not have the 'operations' functions like phpmyadmin has. there are no interfaces to copy / rename database / tables. there are interfaces to run commands for such operations, but as i said, i've forgotten most of those commands and syntax. it's doable but inconvenient.
chive has interface to create store procedures and triggers with function template.
phpmyadmin is well documented (even in several different languages) and has quite a few supports and forums.
there are not documentation for chive (yet?) but there is a forum.
i've never used the forum so i can't comment how helpful or friendly they are.
i like the look and feel of chive. it can do most basic database and table manipulations. but lacking the 'operations' functions makes it inconvenient, as there are many changes i need to do throughout project development.
chive is still new and has potential to grow.
at this stage i will continue to use phpmyadmin. mainly because i work on several servers and it provides an easy interface to switch servers. and i can't live without the 'operations' functions.
Tags: chive, database, free, mysql, phpmyadmin
by prettyscripts on 2012-02-03 12:19:00 • Leave a comment »
instead of going to a different page to view detail from a grid row, i'd like to show detail from pop-in / dialog box within the same page. i found an article from yii's documentation that does exactly that. the article provide solutions to open one or multiple dialogs.
here's document how to show detail using the single dialog with slight modification to the codes in the article for my own reference.
in view file, add the following to CButtonClass section of the array:
PHP:
<?php $this->widget('zii.widgets.grid.CGridView', array( | |
..... | |
'columns' => array( | |
.... | |
array( | |
'class' => 'CButtonColumn', | |
'buttons' => array( | |
'view' => array( | |
'url' => 'url' => 'Yii::app()->createUrl("/path/to/controller/view")', | |
'options' => array( | |
'ajax' => array( | |
'type' => 'POST', | |
'url' => "js:$(this).attr('href')", | |
'update' => '#detail-section', | |
), | |
), | |
| |
), // view button | |
), | |
), | |
) | |
)) ?> |
note:
in the same view file, add the following:
PHP:
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array( | |
'id' => 'dlg-detail', | |
'options' => array( | |
'title' => 'Dialog Box Title', | |
'closeOnEscape' => true, | |
'autoOpen' => false, | |
'model' => false, | |
'width' => 550, | |
'height' => 450, | |
), | |
)) ?> | |
<div id="detail-section"></div> | |
<?php $this->endWidget() ?> |
note:
in controller file:
PHP:
public function actionView($id) { | |
if (Yii::app()->request->isAjaxRequest) { | |
$this->renderPartial('_view', array( | |
'model' => $this->loadModel($id), | |
), false, true); | |
| |
Yii::app()->end(); | |
} | |
} |
note: the view only shows up in dialog. if want to allow to show on a page on its own, add else statement.
by prettyscripts on 2012-01-24 14:28:00 • Leave a comment »
setting a default date value to a date picker field is not so straightforward. as in, simply set a property for the CJuiDatePicker widget.
there are 2 ways to do it. these are based on some forum posts i found a while ago.
say, default the field with today.
in the action function in controller file, prior to render a view:
PHP:
function actionSomething() { | |
.... | |
$model->date_field = date('Y-m-d'); // default to today | |
$this->render(....); | |
} |
in the view file:
PHP:
... | |
<div class="row"> | |
<?php echo $form->labelEx($model,'date_field'); ?> | |
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array( | |
'model' => $model, | |
'attribute' => 'date_field', | |
'htmlOptions' => array( | |
'value' => date('Y-m-d'), // set the default date here | |
), | |
)) ?> | |
<?php echo $form->error($model,'date_field'); ?> | |
</div> | |
... |
note: line 8, set the default value.
by prettyscripts on 2012-01-20 14:17:00 • 1 comment »
i have previously written a post on the same topic with CAutoComplete. since CAutoComplete is deprecated (since V113) and replaced with CJuiAutoComplete, i should keep my notes up-to-dated.
i find that CJuiAutoComplete is easier to implement. the following is based on a this forum post.
PHP:
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array( | |
'model' => $model, | |
'attritube' => 'name_of_attribute', | |
'name' => 'name_of_field', | |
'value' => 'default_display_value', | |
'source' => createUrl('/path/to/controller/autocomplete'), | |
'options' => array( | |
'minLength' => 2, | |
'select' => "js:function(event, ui) { | |
$('#<field_id>').val(ui.item.['<id>']); | |
}", | |
'change' => "js:function(event, ui) { | |
if (!ui.item) { | |
$('#<field_id>').val(''); | |
} | |
}", | |
), | |
)) ?> |
notes:
in controller file, add a new action:
PHP:
function actionAutocomplete() { | |
if (Yii::app()->request->isAjaxRequest && isset($_GET['term'])) { | |
$models = Model::model()->getData($_GET['term']); | |
$result = array(); | |
foreach ($models as $m) | |
$result[] = array( | |
'label' => $m->attribute_displayed_in_drop down_list, | |
'value' => $m->attribute_for_input_field, | |
'id' => $m->attribute_for_hidden_field_or_to_be_saved, | |
'field' => $m->attribute_for_another_field, | |
); | |
| |
echo CJSON::encode($result); | |
} |
notes:
Tags: ajax, autocomplete, jquery, php, yii
by prettyscripts on 2012-01-18 10:52:00 • Leave a comment »
this is an updated post in reference to a previous post about saving a field to null when no value is entered. thanks to those who left comment, this is the correct (and easier!) way to do it.
add a new rule to the model:
PHP:
protected funcion rules() { | |
return array( | |
.... | |
array('name_of_data_field', 'default', 'setOnEmpty' => true), | |
.... | |
); | |
} |
now the field will be saved as null if data is not entered.