Question

i am trying to install yii 2 and to run the basic or advanced application.

i have tried the steps given here Setting up preview of Yii2 to do this.

the steps i followed,

1 - Installed the composer
2 - Use composer to install the app alongwith dependencies(Yii): php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
3 - Access app from http://localhost/my_yii2_trial/web

The problem is, i am getting this syntax error.

Parse error: syntax error, unexpected '[', expecting ')' in D:\xampp\htdocs\my_yii2_trial\vendor\yiisoft\yii2\yii\Yii.php on line 25 

can any body help to resolver this issue pls

Was it helpful?

Solution

Yii2 has started using PHP 5.4's Short array syntax. Your error creeps up because of:

spl_autoload_register(['Yii', 'autoload'], true, true);

in Yii.php, which is the new short array syntax. As you have already figured out, you need to install PHP 5.4 now to run Yii2 apps.


The commit which made the changes to short array syntax.

The docs and composer details that have been changed.

The discussion where the decision to move to PHP 5.4 was made.


As Yii2 is still in heavy development, its requirements are also changing. So be sure to read the readme thoroughly before installing.


See also the Backward Incompatible changes list for PHP 5.4, to make changes to your existing code.

OTHER TIPS

Install PHP 5.4 to resolve this issue.

Yii2 Installation Following command:

(1) First install Composer (LINUX):

Locally:

curl -sS https://getcomposer.org/installer | php

OR

(1) First install Composer (WINDOWS):

C:\Users\username>cd C:\bin

C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php

Note: If the above fails due to readfile, use the http url or enable php_openssl.dll in php.ini

C:\bin>echo @php "%~dp0composer.phar" %>composer.bat*

C:\Users\username>composer -V

Composer version 27d8904


(2) Yii2 framework online downloads:

Basic App:

php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.0-beta

Advanced App:

php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.0-beta


(3) Other App Settings Command:

php init

php yii migrate

Here is command lines to install yii2 on ubuntu:

cd /var/www

/var/www$ ls

/var/www$ cd myyii2

/var/www/myyii2$ ls

/var/www/myyii2$ ls -al

/var/www/myyii2$ ls

/var/www/myyii2$ php init

/* Your choice [0-1, or "q" to quit] 0*/

choose 0 for developemnt and type yes

php yii migrate (/var/www/myyii2$ php yii migrate)

Before this command need to download advance setup like [yii-advanced-app-2.0.7.tgz]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top