public function beforeSave() {
if (parent :: beforeSave()) {
if ($this->isNewRecord) {
$this->created = new CDbExpression('NOW()');
} else {
$this->modified = new CDbExpression('NOW()');
}
return true;
} else {
return false;
}
}
Thursday, 28 November 2013
Wednesday, 5 June 2013
Send file via sftp using PHP
- Download and enable php_ssh2 extension for php http://downloads.php.net/pierre/
$connection=@ssh2_connect("host", 22);
@ssh2_auth_password($connection,"username","pass");
ssh2_scp_send($connection, 'file', 'file', 0644);
Monday, 27 May 2013
Connect Drupal and Alfresco
- Download CMIS API Module http://drupal.org/project/cmis
- Download Alfresco http://www.alfresco.com/products/community
- Add at ./sites/default/settings.php the following:
- Configure module root directory add " \ "
'default' => array(
'user' => 'user',
'password' => 'password',
'url' => 'http://127.0.0.1:8080/alfresco/s/cmis',
)
);
Thursday, 9 May 2013
Node.js Hello world and MySQL Example
var http = require("http");
var mysql = require('mysql'); // required modules
var connection = mysql.createConnection({ // connect to mysql database
host : 'localhost',
port : '3308',
database : 'db',
user : 'user',
password : 'password',
});
var data; // store query result
connection.query('SELECT * FROM table', function(err, rows, fields) { // query DB
if (err) throw err;
data = JSON.stringify(rows); // save query as JSON
});
http.createServer(function (request, response) { // create server
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<h1>Hello World</h1>");
response.write("<h2>Jefren Inocando</h2>");
response.write('<pre>' + data + '</pre>');
response.end();
}).listen(81);
console.log('Server running at http://127.0.0.1:81');
var mysql = require('mysql'); // required modules
var connection = mysql.createConnection({ // connect to mysql database
host : 'localhost',
port : '3308',
database : 'db',
user : 'user',
password : 'password',
});
var data; // store query result
connection.query('SELECT * FROM table', function(err, rows, fields) { // query DB
if (err) throw err;
data = JSON.stringify(rows); // save query as JSON
});
http.createServer(function (request, response) { // create server
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<h1>Hello World</h1>");
response.write("<h2>Jefren Inocando</h2>");
response.write('<pre>' + data + '</pre>');
response.end();
}).listen(81);
console.log('Server running at http://127.0.0.1:81');
Friday, 25 January 2013
Yii Autocomplete return multiple values and fill multiple fields
View:
<div class="row">
<?php echo $form->labelEx($model, 'attribute'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model' => $model,
'attribute' => 'emp',
'sourceUrl' => Yii::app()->createUrl('/controller/action'),
'options' => array(
'minLength' => '1',
'select' => 'js:function(event, ui) {
$("#field1").val(ui.item.label);
$("#field2").val(ui.item.value);
return false;
}'
),
'htmlOptions' => array('size' => 60),
));
?>
<?php echo $form->error($model, 'attribute'); ?>
</div>
Controller:
public function actionAutocomplete($term) {
//the $term parameter is what the user typed in on the control
//send back an array of data:
$criteria = new CDbCriteria;
$criteria->compare('field2', $term, true);
$model = Model::model()->findAll($criteria);
foreach ($model as $value) {
$array[] = array('value' => trim($value->field1), 'label' => trim($value->field2));
}
echo CJSON::encode($array);
Yii::app()->end();
}
<div class="row">
<?php echo $form->labelEx($model, 'attribute'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model' => $model,
'attribute' => 'emp',
'sourceUrl' => Yii::app()->createUrl('/controller/action'),
'options' => array(
'minLength' => '1',
'select' => 'js:function(event, ui) {
$("#field1").val(ui.item.label);
$("#field2").val(ui.item.value);
return false;
}'
),
'htmlOptions' => array('size' => 60),
));
?>
<?php echo $form->error($model, 'attribute'); ?>
</div>
Controller:
public function actionAutocomplete($term) {
//the $term parameter is what the user typed in on the control
//send back an array of data:
$criteria = new CDbCriteria;
$criteria->compare('field2', $term, true);
$model = Model::model()->findAll($criteria);
foreach ($model as $value) {
$array[] = array('value' => trim($value->field1), 'label' => trim($value->field2));
}
echo CJSON::encode($array);
Yii::app()->end();
}
PHP - Enable ldap.dll for xampp or Windows server
- From C:\xampp\php copy the following files to C:\Windows\system
- libeay32.dll
- libsasl.dll
- ssleay32.dll
- Enable php_ldap.dll at php.ini
Thursday, 24 January 2013
Yii connect to MS SQL Server
- Dowload Drivers and DLL for PHP http://msdn.microsoft.com/en-us/library/cc296170.aspx
- Edit php.ini enable extension
- Edit config/main.php db connection string
'db' => array(
'connectionString' => 'sqlsrv:Server=tcp:123.345.444.333;Database=myDB',
'username' => 'username',
'password' => 'password',
),
Wednesday, 16 January 2013
Yii Ajax loader
<?php
Yii::app()->clientScript->registerScript('loaderScript', '
$("#loader")
.hide()
.ajaxStart(function() {
$(this).show();
})
.ajaxStop(function() {
$(this).hide();
});', CClientScript::POS_END);
?>
<?php echo CHtml::image('images/ajax-loader.gif', '', array('id' => 'loader', 'style' => 'margin-left:15px;'));?>
Thursday, 3 January 2013
Yii CGridView with CCheckBoxColumn with ajaxbutton
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'orders-products-grid',
'dataProvider' => $model->search(),
'columns' => array(
array(
'header' => 'Item #',
'value' => '++$row',
),
'products_name',
'products_quantity',
array(
'header' => 'Price',
'value' => '"$".number_format($data->final_price*$data->products_quantity,2)',
),
array(
'header' => 'Confirmed?',
'value' => '$data->bought == 0? "No" : "Yes"',
),
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checked' => '$data->bought==1',
'id' => 'boughtCheck'
)
),
));
?>
<?php
echo CHtml::ajaxButton('Confirm', yii::app()->createUrl('site/checkBought'), array(
'type' => 'POST',
'data' => 'js:{value : $.fn.yiiGridView.getChecked("orders-products-grid","boughtCheck")}',
'success'=>'js:function(data){
$.fn.yiiGridView.update("orders-products-grid");
}'
));
Subscribe to:
Posts (Atom)