Posts Tagged with yii

Displaying 21-30 of 114 results.
Resolved: Yii2 Error Exception: Class 'Custom class' not found
posted by admin on February 15, 2017
I use in migration classes custom helper class Table, and in migration up process got an error like

./yii migrate

Result until error

Yii Migration Tool (based on Yii v2.0.11.2)

Total 2 new migrations to be applied:

Apply the above migrations? (yes|no) [no]:yes
*** applying m170213_124818_init

Error Message:

Exception: Class 'yii\helpers\Table' not found (/var/www/html/basic/migrations/m170213_124818_init.php:10)

My class is in root directory in helpers directory

namespace yii\helpers;
class Table
public static $user = 'user';
public static $role = 'role';
public static $status = 'status';
public static $domain = 'domain';

In migration class

use yii\db\Migration;
use yii\helpers;

class m170213_124818_init extends Migration
public function safeUp()
/** User Create*/
$this->createTable('{{%'.helpers\Table::$user.'}}', [
'id' => $this->primaryKey(10)->notNull()->unsigned(),
. . .
], 'ENGINE=InnoDB');

How to resolve itRead more
Resolved: Yii2 Helper folder, helper namespace, helper class
posted by admin on February 14, 2017
In yii1 I created helpers folder in public and move all my helper classes and autoload them from main.php setting file

// autoloading model and component classes

I have three questions

  1. Where create helpers classes folder
  2. How to create helpers classes
  3. How to autoload or use helpers classes
Read 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
* 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', '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();

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

# yii config

How to fix it?Read more
Resolved: Yii2 slash 2f url problem
posted by admin on February 6, 2017
After installation Yii2, I try to navigate with pages of application, and in url I have problem with slashes

I want to slashes in url in place of %2FRead more
Wiki: Installing Yii2 in XAMPP to htdocs directorywiki
posted by admin on February 1, 2017
The First, dont forget to install "fxp/composer-asset-plugin:^1.2.0"

php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"

Waiting for result

Changed current directory to C:/Users/Arthur/AppData/Roaming/Composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing fxp/composer-asset-plugin (v1.2.2) Downloading: 100%
Writing lock file
Generating autoload files

The Second, start instalation

c:\xampp\php>php composer.phar create-project --prefer-dist yiisoft/yii2-app-bas
ic ../htdocs/yiibasic

Waiting for result

Installing yiisoft/yii2-app-basic (2.0.10)
- Installing yiisoft/yii2-app-basic (2.0.10) Downloading: 100%
Created project in ../htdocs/yiibasic
Loading composer repositories with package information
Updating dependencies (including require-dev)
Reading bower.json of bower-asset/jquery (1.11.3)
Could not fetch
17f17af05e98007136096784f9051fab, please create a GitHub OAuth token to go over
the API rate limit
Head to
to retrieve a token. It will be stored in "C:/Users/╚фЁшё/AppData/Roaming/Compos
er/auth.json" for future use by Composer.
Token (hidden):
Token stored successfully.
Package operations: 58 installs, 0 updates, 0 removals
- Installing yiisoft/yii2-composer (2.0.5) Downloading: 100%
- Installing swiftmailer/swiftmailer (v5.4.5) Downloading: 100%
- Installing bower-asset/jquery (2.2.4) Downloading: 100%
- Installing bower-asset/yii2-pjax (v2.0.6) Downloading: 100%
- Installing bower-asset/punycode (v1.3.2) Downloading: 100%
- Installing bower-asset/jquery.inputmask (3.2.7) Downloading: 100%
- Installing cebe/markdown (1.1.1) Downloading: 100%
- Installing ezyang/htmlpurifier (v4.8.0) Downloading: 100%
- Installing yiisoft/yii2 (2.0.10) Downloading: 100%
- Installing yiisoft/yii2-swiftmailer (2.0.6) Downloading: 100%
- Installing bower-asset/bootstrap (v3.3.7) Downloading: 100%
- Installing yiisoft/yii2-bootstrap (2.0.6) Downloading: 100%
- Installing yiisoft/yii2-debug (2.0.7) Downloading: 100%
- Installing bower-asset/typeahead.js (v0.11.1) Downloading: 100%
- Installing phpspec/php-diff (v1.1.0) Downloading: 100%
- Installing yiisoft/yii2-gii (2.0.5) Downloading: 100%
- Installing fzaninotto/faker (v1.6.0) Downloading: 100%
- Installing yiisoft/yii2-faker (2.0.3) Downloading: 100%
- Installing sebastian/diff (1.4.1) Downloading: 100%
- Installing sebastian/recursion-context (2.0.0) Downloading: 100%
- Installing sebastian/exporter (2.0.0) Downloading: 100%
- Installing sebastian/comparator (1.2.4) Downloading: 100%
- Installing behat/gherkin (v4.4.5) Downloading: 100%
- Installing symfony/polyfill-mbstring (v1.3.0) Downloading: 100%
- Installing symfony/dom-crawler (v3.2.2) Downloading: 100%
- Installing symfony/css-selector (v3.2.2) Downloading: 100%
- Installing symfony/browser-kit (v3.2.2) Downloading: 100%
- Installing symfony/yaml (v3.2.2) Downloading: 100%
- Installing symfony/event-dispatcher (v3.2.2) Downloading: 100%
- Installing psr/log (1.0.2) Downloading: 100%
- Installing symfony/debug (v3.2.2) Downloading: 100%
- Installing symfony/console (v3.2.2) Downloading: 100%
- Installing symfony/finder (v3.2.2) Downloading: 100%
- Installing psr/http-message (1.0.1) Downloading: 100%
- Installing guzzlehttp/psr7 (1.3.1) Downloading: 100%
- Installing sebastian/version (2.0.1) Downloading: 100%
- Installing sebastian/environment (2.0.0) Downloading: 100%
- Installing sebastian/code-unit-reverse-lookup (1.0.0) Downloading: Connectin
Downloading: 100%
- Installing phpunit/php-token-stream (1.4.9) Downloading: 100%
- Installing phpunit/php-text-template (1.2.1) Downloading: 100%
- Installing phpunit/php-file-iterator (1.4.2) Downloading: 100%
- Installing phpunit/php-code-coverage (4.0.5) Downloading: 100%
- Installing sebastian/resource-operations (1.0.0) Downloading: 100%
- Installing sebastian/object-enumerator (2.0.0) Downloading: 100%
- Installing sebastian/global-state (1.1.1) Downloading: 100%
- Installing doctrine/instantiator (1.0.5) Downloading: 100%
- Installing phpunit/phpunit-mock-objects (3.4.3) Downloading: 100%
- Installing phpunit/php-timer (1.0.8) Downloading: 100%
- Installing webmozart/assert (1.2.0) Downloading: 100%
- Installing phpdocumentor/reflection-common (1.0) Downloading: 100%
- Installing phpdocumentor/type-resolver (0.2.1) Downloading: 100%
- Installing phpdocumentor/reflection-docblock (3.1.1) Downloading: Connecting
Downloading: 100%
- Installing phpspec/prophecy (v1.6.2) Downloading: 100%
- Installing myclabs/deep-copy (1.6.0) Downloading: 100%
- Installing phpunit/phpunit (5.7.9) Downloading: 100%
- Installing codeception/base (2.2.8) Downloading: 100%
- Installing codeception/verify (0.3.2) Downloading: 100%
- Installing codeception/specify (0.4.6) Downloading: 100%
symfony/browser-kit suggests installing symfony/process ()
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
symfony/console suggests installing symfony/filesystem ()
symfony/console suggests installing symfony/process ()
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.4.0)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
phpunit/phpunit suggests installing ext-xdebug (*)
codeception/base suggests installing flow/jsonpath (For using JSONPath in REST m
codeception/base suggests installing phpseclib/phpseclib (for SFTP option in FTP
codeception/base suggests installing league/factory-muffin (For DataFactory modu
codeception/base suggests installing league/factory-muffin-faker (For Faker supp
ort in DataFactory module)
codeception/base suggests installing symfony/phpunit-bridge (For phpunit-bridge
Writing lock file
Generating autoload files
> yii\composer\Installer::postCreateProject
chmod('runtime', 0777)...done.
chmod('web/assets', 0777)...done.
chmod('yii', 0755)...done.
Read more
Wiki: Composer can be installed by following the instructionswiki
posted by admin on February 1, 2017
This process looks as follows:

curl -sS | php

nstaller | php
Alternatively, if you don't have cURL available on your system, it can be installed through PHP itself:

php -r "readfile('');" | php
Read more
Wiki: Установка Yii под XAMPP в Windows 8wiki
posted by admin on January 21, 2016
Здесь я подробно расскажу, как установить Yii - фрэймфорк под популярную сборку веб-сервера XAMPP в операционной системе Windows 8.

Для работы Yii - фрэймфорка, необходим PHP версии 5.1 и выше, a в ближайшем будущем появится новая версия фрэймворка в которой уже понадобится как минимум версия 5.3.

Для работы с проектами на локальном компьютере на данный момент я использую XAMPP 3.0.12 c версией php 5.4. Скачать XAMPP можно здесь.

Лично я настроил XAMMP так, что все проекты у меня хранятся на диске D в папке PHP, чего и вам советую.

Что касается самого yii-фрэймворка, скачть его можно здесь. Пример развертывания проекта у меня будет происходить на версии yii 1.1.4.

Создаем в папке php новую папку с проектом. Я назвал ее learn.loc. Далее, для нового проекта настраиваем виртуальные хосты и т.д.. В общем, все стандартные действия, чтобы после введения в строку браузера http://learn.loc ваш проект не послал вас на 404 или куда-то в подобном направлении.

Распакуем в корень папки learn.loc скачанный фрэймворк.

Теперь настало время консоли windows. Вывзываем консоль (надеюсь, как это сделать объяснять не надо) и вводим такое заклинание:

C:/xampp/php/php.exe C:/xampp/htdocs/learn.loc/framework/yiic webapp C:/xampp/htdocs/learn.loc/

Где C:/xampp/php/php.exe - путь до исполняемого файла php, C:/xampp/htdocs/learn.loc/framework/yiic - путь до файла во вреймворке, который развертывает проект, а C:/xampp/htdocs/learn.loc/ - путь куда мы хотим развернуть проект.

Далее, в консоли у нас спросят, внтатуре ли мы отвечем за базар. Вводим y (yes) и наслаждаемся бегущими строчками на черном экране. Типа вы архитектор матрицы.

На этом всё. Делее можете проверить, работает ли проект, введя в браузер http://learn.locRead more
Wiki: CActiveRelation HAS_MANY BELONGS_TO based on secondary keywiki
posted by admin on November 16, 2016
In the Model class, I overrode the getTableSchema and manually defined the foreign keys like so:

public function getTableSchema()
$table = parent::getTableSchema();

$table->columns['sid']->isForeignKey = true;
$table->foreignKeys['sid'] = array('Click', 'm_sid');

return $table;

And in the corresponding table:

public function getTableSchema()
$table = parent::getTableSchema();

$table->columns['m_sid']->isForeignKey = true;
$table->foreignKeys['m_sid'] = array('Message', 'sid');

return $table;

Now the standard relation definitions work directly!

'clicks'=>array( self::HAS_MANY, 'Click', 'm_sid' ),

as well as

'message'=>array( self::BELONGS_TO, 'Message', 'sid'),
Read more
Resolved: Hosting MySQL connection error: SQLSTATE[HY000] [2002] Connection refused
posted by admin on November 11, 2016
I am trying to run my Yii 1 website and connect to DB, which is not in my hosting and have this error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused

For example, my MySQL config in working fine

return array(
'connectionString' => 'mysql:host=*******;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',

Another server connection and error

return array(
'connectionString' => 'mysql:host=anotherhostname;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',


CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused
Read more
Resolved: Yii 1.1 Redirect to referrer url
posted by admin on November 10, 2016
I want to redirect from referrer page


I want something like

Read more