Posts Tagged with app

Displaying 1-10 of 12 results.
Resolved: Odnoklassniki OK api apiok users.getInfo all fields without errors
posted by admin on April 17, 2017
I try to get all allowed fields from user by id, and got some error

{
error_code:100
error_msg:PARAM : Invalid parameter fields value : [accessible,age,allows_anonym_access,allows_messaging_only_for_friends,birthday,blocked,blocks,can_vcall,can_vmail,capabilities,common_friends_count,current_location,current_status,current_status_date,current_status_date_ms,current_status_id,current_status_track_id,email,feed_subscription,first_name,friend,friend_invitation,gender,has_email,has_service_invisible,invited_by_friend,is_activated,last_name,last_online,last_online_ms,location,login,modified_ms,name,notifications_subscription,online,photo_id,pic1024x768,pic128max,pic128x128,pic180min,pic190x190,pic224x224,pic240min,pic288x288,pic320min,pic50x50,pic600x600,pic640x480,pic_1,pic_2,pic_3,pic_4,pic_5,pic_base,pic_full,pic_max,premium,presents,private,ref,registered_date,registered_date_ms,relationship,show_lock,uid,url_chat,url_chat_mobile,url_profile,url_profile_mobile,vip]
error_data:null
}

All fields I got from apiok official page

[{
accessible:Boolean
age:Integer
allows_anonym_access:Boolean
allows_messaging_only_for_friends:Boolean
birthday:String
blocked:Boolean
blocks:Boolean
can_vcall:Boolean
can_vmail:Boolean
capabilities:String
common_friends_count:Integer
current_location:{
altitude:Float
cellId:Integer
city:String
country:String
ipAddress:String
latitude:Float
longitude:Float
}
current_status:String
current_status_date:Date
current_status_date_ms:Long
current_status_id:String
current_status_track_id:String
email:String
feed_subscription:Boolean
first_name:String
friend:Boolean
friend_invitation:Boolean
gender:String
has_email:Boolean
has_service_invisible:Boolean
invited_by_friend:Boolean
is_activated:Boolean
last_name:String
last_online:String
last_online_ms:Long
locale:String
location:{
city:String
country:String
countryCode:String
countryName:String
}
login:String
modified_ms:Long
name:String
notifications_subscription:Boolean
online:String
photo_id:String
pic1024x768:String
pic128max:String
pic128x128:String
pic180min:String
pic190x190:String
pic224x224:String
pic240min:String
pic288x288:String
pic320min:String
pic50x50:String
pic600x600:String
pic640x480:String
pic_1:String
pic_2:String
pic_3:String
pic_4:String
pic_5:String
pic_base:String
pic_full:String
pic_max:String
premium:Boolean
presents:[{}]
private:Boolean
ref:String
registered_date:Date
registered_date_ms:Long
relations:[{}]
relationship:{}
show_lock:Boolean
uid:String
url_chat:String
url_chat_mobile:String
url_profile:String
url_profile_mobile:String
vip:Boolean
}]
Read more
Wiki: PHPStorm FIX - not working hotkey CTRL + keys functionalitywiki
posted by admin on February 27, 2017
In most java-application with a GUI on Ubuntu in Russian layout is not working hotkeys, even the standard Ctrl + C and Ctrl + V. But a good man, named Michael Zheludkov wrote fix this bug, for which he had great thanks.
Installation
Clone repository in the folder ~ / fix /:

git clone https://github.com/zheludkovm/LinuxJavaFixes.git fix

Открываем конфиг приложения: or edit with GEDIT editor

nano /opt/PhpStorm/bin/phpstorm64.vmoptions

Add the following line to the fix:

-javaagent:/home/{user}/fix/build/LinuxJavaFixes-1.0.0-SNAPSHOT.jar

Replace {user} to your Ubuntu user UsernameRead more
Resolved: Yii2 Console command error and warning with SetEnv APPLICATION_ENV usage
posted by admin on February 13, 2017
Yii2 Terminal Command

> ./yii

Command result errors ana warnings

PHP Warning: require(/var/www/html/myproject/config/env/prod/env.php): failed to open stream: No such file or directory in /var/www/html/myproject/config/env.php on line 1
PHP Fatal error: require(): Failed opening required '/var/www/html/vktracker2/config/env/prod/env.php' (include_path='.:/usr/share/php'myproject/www/html/myproject/config/env.php on line 1

In root my yii file

#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*/
// Define our application_env variable as provided by nginx/apache
if (!defined('APPLICATION_ENV'))
{
if (getenv('APPLICATION_ENV') != false)
define('APPLICATION_ENV', getenv('APPLICATION_ENV'));
else
define('APPLICATION_ENV', 'prod');
}
$env = require(__DIR__ . '/config/env.php');
defined('YII_DEBUG') or define('YII_DEBUG', $env['debug']);
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/config/console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

In result yii don't recognize my SetEnv, which is in virtual hosts config file
/etc/apache2/apache2.config

# yii config
SetEnv APPLICATION_ENV dev


How to fix it?Read more
Wiki: Yii 1.1 app db createCommand execution of SQL statement wayswiki
posted by admin on November 7, 2016
Once a database connection is established, SQL statements can be executed using CDbCommand. One creates a CDbCommand instance by calling CDbConnection::createCommand() with the specified SQL statement:

$connection=Yii::app()->db; // assuming you have configured a "db" connection
// If not, you may explicitly create a connection:
// $connection=new CDbConnection($dsn,$username,$password);
$command=$connection->createCommand($sql);
// if needed, the SQL statement may be updated as follows:
// $command->text=$newSQL;

A SQL statement is executed via CDbCommand in one of the following two ways:
  • execute(): performs a non-query SQL statement, such as INSERT, UPDATE and DELETE. If successful, it returns the number of rows that are affected by the execution.
  • query(): performs an SQL statement that returns rows of data, such as SELECT. If successful, it returns a CDbDataReader instance from which one can traverse the resulting rows of data. For convenience, a set of queryXXX() methods are also implemented which directly return the query results.

An exception will be raised if an error occurs during the execution of SQL statements.

$rowCount=$command->execute(); // execute the non-query SQL
$dataReader=$command->query(); // execute a query SQL
$rows=$command->queryAll(); // query and return all rows of result
$row=$command->queryRow(); // query and return the first row of result
$column=$command->queryColumn(); // query and return the first column of result
$value=$command->queryScalar(); // query and return the first field in the first row
//in Russian
$rowCount=$command->execute(); // выполнение запроса типа `INSERT`, `UPDATE` или `DELETE`
$dataReader=$command->query(); // выполнение запроса типа `SELECT`
$rows=$command->queryAll(); // возвращает все строки результата запроса
$row=$command->queryRow(); // возвращает первую строку результата запроса
$column=$command->queryColumn(); // возвращает первый столбец результата запроса
$value=$command->queryScalar(); // возвращает значение первого поля первой строки результата запроса
Read more
Wiki: Yii 1.1: How to work with flash messageswiki
posted by admin on May 22, 2016
Summary
Set your messages in a controller:

Yii::app()->user->setFlash('success', "Data1 saved!");
Yii::app()->user->setFlash('error', "Data2 failed!");
Yii::app()->user->setFlash('notice', "Data3 ignored.");

Display them in your view:

<?php
foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
}
?>

Setting flash messages
A flash message is used in order to keep a message in session through one or several requests of the same user. By default, it is removed from session after it has been displayed to the user. Flash messages are usually used in combination with HTTP redirections, because in this case there is no view, so messages can only be displayed in the request that follows redirection.

A flash message has a name and a content (AKA key and value). It is an entry of an associative array. The name is a string: often "notice", "success", or "error", but it can be anything. The content is usually a string. You can put HTML tags in your message if you display it raw. You can also set the message value to a number or an array: it will be serialized and kept in session like a string.

Flash messages can be set using the setFlash() Method of CWebUser. For example, if you would like to inform the user that his changes were successfully saved, you could add the following line to your Controller:

<?php
Yii::app()->user->setFlash('success', "Data saved!");
$this->redirect(array('thing/view', 'id' => 1));

In this example we used the key 'success'. If you want to define more than one flash messages, you will have to use different keys.
Displaying flash messages
To check for flash messages we use the hasFlash() Method and to obtain the flash message we use the getFlash() Method. Since Yii v1.1.3, there is also a method getFlashes() to fetch all the messages.

By default, fetching a message deletes it from the session. This means that a message is meant to be displayed only on the first page served to the user. The fetching methods have a boolean parameter that can change this behavior. See the API links in the previous paragraph.

Displaying statically
So showing of the flash message defined above in a view is done by

<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="info">
<?php echo Yii::app()->user->getFlash('success'); ?>
</div>
<?php endif; ?>

These few lines of code will make a flash message with the key "success" visible to the user within a div of class "info". The message will be displayed until this or another page is (re)loaded in the browser.

If you want to always display all the flash messages, then you should add a block to your layout (by default protected/views/layout/main.php). Here is a more elaborate example:

<?php
$flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
echo '<ul class="flashes">';
foreach($flashMessages as $key => $message) {
echo '<li><div class="flash-' . $key . '">' . $message . "</div></li>\n";
}
echo '</ul>';
}
?>

The default CSS created by the Yii script yiic webapp has directives for three classes of flash messages on a div tag: flash-error, flash-notice, flash-success.

The best way to know if some flash messages are set is to check if Yii::app()->user->getFlashes() is empty. Since v1.1.7, Yii keeps an associative array of the flash keys in the form array("key1" => 0, ...), or null if not flash message is set. You can fetch this with Yii::app()->user->getState(CWebUser::FLASH_COUNTERS) but this is not recommended, as Yii could change this internal process.

Displaying dynamically (with Javascript)
If you want the flash message to appear somewhere above the content and then automatically fade out after a few seconds, you will have to add the following lines to your view:

<?php
Yii::app()->clientScript->registerScript(
'myHideEffect',
'$(".info").animate({opacity: 1.0}, 3000).fadeOut("slow");',
CClientScript::POS_READY
);
?>

With these lines of code we register a piece of jQuery (already included with YII) javascript code, using 'myHideEffect' as ID. It will be inserted in the jQuery's ready function (CClientScript::POS_READY). Due to the chainablity of jQuery the little script will run two effects on the .info DIV sequentially:

.animate({opacity: 1.0}, 3000)

Normally this would animate the .info DIV to a full opacity within 3 seconds. But the DIV is already rendered with full opacity upon page load, so calling this effect will just cause a delay for 3 seconds.

.fadeOut("slow")

This is the fadeOut effect which will hide the .info DIV at slow speed.Read more
Resolved: Yii get current controller and action
posted by admin on April 25, 2016
Is their a way to get the name of the current controller and action that the app is executing? I was wondering if Yii:app stores this or not, but I can't find any reference to it. I need this information to use in the main layout view for a widget.Read more
Resolved: Yii check if user logged in of guest
posted by admin on April 14, 2016
I want to check my visitor type, guest or logged in user.Read more
Resolved: Yii translation not working
posted by admin on April 12, 2016
My Yii app translation code is stop working

<?php echo Yii::t('t', 'Added'); ?>


My Messages folder and file:

- messages
- ru
- t.php
Read more
Wiki: Yii 1.1 cgridview filter dropdown with relation table datawiki
posted by admin on April 7, 2016
View: admin.php

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'media-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'caption',
'created',
'updated',
array( 'name' => 'visibility_id',
'value' => '$data->visibility_id',
'filter' => CHtml::listData(Visibility::model()->findall(), 'id', 'name'),
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>


Model: Visibility.php

class Visibility extends CActiveRecord
{
public function tableName()
{
return 'tbl_visibility';
}

public function rules()
{
return array(
//your rules here
);
}

public function relations()
{
return array(
'media' => array(self::HAS_MANY, 'Media', 'visibility_id'),
);
}

public static function model($className=__CLASS__)
{
return parent::model($className);
}
}


Model: Media.php

class Media extends CActiveRecord
{
public function tableName()
{
return 'tbl_media';
}
public function rules()
{
return array(
//your rules
//...

);
}
public function relations()
{
return array(
'visibility' => array(self::BELONGS_TO, 'Visibility', 'visibility_id'),
);
}

public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Read more
Resolved: Yii get value from url GET name
posted by admin on March 30, 2016
I'd like to know if there is an Yii function to get a value from url. The url that I have is:

http://www.domain.com/index.php/module/controller/update/id/111

I need to get the value '111' before it gets to the update action, is there an Yii method to do it?Read more