chive: phpmyadmin alternative?

by prettyscripts on 2012-02-10 15:13:00 • Leave a comment »

software

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.

installation and configuration

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.

user interface

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.

database manipulation

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.

documentation and help

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.

the verdict?

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

yii: CGridView and show detail in CJuiDialog

by prettyscripts on 2012-02-03 12:19:00 • Leave a comment »

misc

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.

overwrite the view button

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:

  • line 11: the ajax section. yii will automatically generate the required jquery based on these data.
  • line 14: the # name should match that in the following section.

add dialog section

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:

  • line 3: for options check this demo page.
  • line 12: the id should match line 14 from above code.

change the view action

in controller file:

PHP:

public function actionView($id) {
    if (Yii::app()->request->isAjaxRequest) {
        $this->renderPartial('_view'array(
            'model' => $this->loadModel($id),
        ), falsetrue);
 
        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.

Tags: detail, dialog, grid, jquery, php, yii

yii: default value for date picker field and CJuiDatePicker

by prettyscripts on 2012-01-24 14:28:00 • Leave a comment »

phpyii

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.

method 1 - give the attribute a default value

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(....);
}

method 2 - use html option

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.

Tags: date, default, php, yii

yii: autocomplete field with CJuiAutoComplete

by prettyscripts on 2012-01-20 14:17:00 • 1 comment »

phpyii

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.

view file or the form

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:

  • line 4: do not use codes line 2-3 this field is for display a value. ensure there's a hidden field on the form to be saved to the database.
  • lines 9 - 15: optional. for situation such as to display value on a field but save the id to database.
  • line 10: eg set hidden field with the actual data value to be saved to database, see next section regarding <id>
  • lines 12 - 15: clear field value if data is empty

autocomplete action

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:

  • line 7: can be formatted string to be displayed on the drop down list.
  • line 8: value to be displayed in current input field
  • line 9-10: optional. values to be set on another field on the same form. refering to line 8 above. can be accessed as array.

Tags: ajax, autocomplete, jquery, php, yii

yii: save empty field as null

by prettyscripts on 2012-01-18 10:52:00 • Leave a comment »

phpyii

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.

Tags: code, null, php, save, yii