Yii Framework Forum: Problem Z Kodem W Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problem Z Kodem W Yii Error Rate Topic: -----

#1 User is offline   bzyku51 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 30-May 14

Posted 30 May 2014 - 04:04 AM

Witam, podczas robienia tutoriala z yii, gdy chcę otworzyć: //hostname/testdrive/index.php?r=gii wyskakuje mi błąd: Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\xampp\htdocs\blog\protected\config\main.php on line 30


oto mój cały kod:

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',

// preloading 'log' component
'preload'=>array('log'),

// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),

'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'1234',
),
),
);

// application components
'components'=>array(
),

'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
/*
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
*/
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
// uncomment the following to use a MySQL database
/*
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testdrive',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
*/
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
),
);
0

#2 User is offline   rob006 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 30 May 2014 - 04:35 AM

Masz błędnie zadeklarowaną tablicę - w okolicach 27 linii masz nawias i średnik zamykające tablicę, a później deklarujesz ją sobie dalej. Tej linijki prawdopodobnie w ogóle tu nie powinno być.

W ogóle masz bałagan z tą tablicą, zawartość "components" jest deklarowana poza elementem "components", a dalej już nawet nie sprawdzałem. Skorzystaj może z jakiegoś IDE podpowiadającego składnię i ułatwiającego formatowanie, bo bez uporządkowanych wcięć będziesz miał z tym tylko same problemy.
0

#3 User is offline   .viktor. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 25-August 10
  • Location:Sokołów Podlaski, Poland

Posted 30 May 2014 - 04:41 AM

Zacząłem poprawić więc wrzucam poprawiony main.php, jak kolega wspomniał, pilnuj nawiasów i formatowania kodu a w postach dla wklejanego kodu używaj odpowiednich tagów "Other styles"

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'My Web Application',

    // preloading 'log' component
    'preload' => array('log'),

    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
    ),

    'modules' => array(
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => '1234',
        ),
    ),

    // application components
    'components' => array(),

    'user' => array(
        // enable cookie-based authentication
        'allowAutoLogin' => true,
    ),

// uncomment the following to enable URLs in path-format
    /*
    'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    ),
    */

    'db' => array(
        'connectionString' => 'sqlite:' . dirname(__FILE__) . '/../data/testdrive.db',
    ),

    // uncomment the following to use a MySQL database
    /*
    'db'=>array(
    'connectionString' => 'mysql:host=localhost;dbname=testdrive',
    'emulatePrepare' => true,
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    ),
    */

    'errorHandler' => array(
        // use 'site/error' action to display errors
        'errorAction' => 'site/error',
    ),

    'log' => array(
        'class' => 'CLogRouter',
        'routes' => array(
            array(
                'class' => 'CFileLogRoute',
                'levels' => 'error, warning',
            ),
            // uncomment the following to show log messages on web pages
            /*
            array(
            'class'=>'CWebLogRoute',
            ),
            */
        ),
    ),

    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    )

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
);

0

#4 User is offline   rob006 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 72
  • Joined: 01-January 13
  • Location:Lublin, Poland

Posted 30 May 2014 - 04:44 AM

View Post.viktor., on 30 May 2014 - 04:41 AM, said:

    // application components
    'components' => array(),



Twój config jest ciągle nieprawidłowy - definiujesz komponenety poza elementem "components".
0

#5 User is offline   bzyku51 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 30-May 14

Posted 30 May 2014 - 06:41 AM

View Post.viktor., on 30 May 2014 - 04:41 AM, said:

Zacząłem poprawić więc wrzucam poprawiony main.php, jak kolega wspomniał, pilnuj nawiasów i formatowania kodu a w postach dla wklejanego kodu używaj odpowiednich tagów "Other styles"

<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'My Web Application',

    // preloading 'log' component
    'preload' => array('log'),

    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
    ),

    'modules' => array(
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => '1234',
        ),
    ),

    // application components
    'components' => array(),

    'user' => array(
        // enable cookie-based authentication
        'allowAutoLogin' => true,
    ),

// uncomment the following to enable URLs in path-format
    /*
    'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    ),
    ),
    */

    'db' => array(
        'connectionString' => 'sqlite:' . dirname(__FILE__) . '/../data/testdrive.db',
    ),

    // uncomment the following to use a MySQL database
    /*
    'db'=>array(
    'connectionString' => 'mysql:host=localhost;dbname=testdrive',
    'emulatePrepare' => true,
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    ),
    */

    'errorHandler' => array(
        // use 'site/error' action to display errors
        'errorAction' => 'site/error',
    ),

    'log' => array(
        'class' => 'CLogRouter',
        'routes' => array(
            array(
                'class' => 'CFileLogRoute',
                'levels' => 'error, warning',
            ),
            // uncomment the following to show log messages on web pages
            /*
            array(
            'class'=>'CWebLogRoute',
            ),
            */
        ),
    ),

    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    )

// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
);



Niestety, po wklejeniu kodu od Ciebie Viktor wyświetla mi się następująca rzecz ( w załączniku screenyAttached File  nafor1.jpg (157.67K)
Number of downloads: 3) Attached File  nafor2.jpg (257.59K)
Number of downloads: 3
0

#6 User is offline   .viktor. 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 25-August 10
  • Location:Sokołów Podlaski, Poland

Posted 30 May 2014 - 06:54 AM

No faktycznie jeszcze jeden nawias :), teraz powinno być dobrze.
<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'My Web Application',

    // preloading 'log' component
    'preload' => array('log'),

    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
    ),

    'modules' => array(
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => '1234',
        ),
    ),

    // application components
    'components' => array(
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
        ),

        // uncomment the following to enable URLs in path-format
        /*
        'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
        ),
        */

        'db' => array(
            'connectionString' => 'sqlite:' . dirname(__FILE__) . '/../data/testdrive.db',
        ),

        // uncomment the following to use a MySQL database
        /*
        'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=testdrive',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        ),
        */

        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),

        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                array(
                    'class' => 'CFileLogRoute',
                    'levels' => 'error, warning',
                ),
                // uncomment the following to show log messages on web pages
                /*
                array(
                'class'=>'CWebLogRoute',
                ),
                */
            ),
        ),
    ),

    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    )

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
);

0

#7 User is offline   bzyku51 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 30-May 14

Posted 30 May 2014 - 07:01 AM

View Post.viktor., on 30 May 2014 - 06:54 AM, said:

No faktycznie jeszcze jeden nawias :), teraz powinno być dobrze.
<?php

// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
    'name' => 'My Web Application',

    // preloading 'log' component
    'preload' => array('log'),

    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
    ),

    'modules' => array(
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => '1234',
        ),
    ),

    // application components
    'components' => array(
        'user' => array(
            // enable cookie-based authentication
            'allowAutoLogin' => true,
        ),

        // uncomment the following to enable URLs in path-format
        /*
        'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
        ),
        */

        'db' => array(
            'connectionString' => 'sqlite:' . dirname(__FILE__) . '/../data/testdrive.db',
        ),

        // uncomment the following to use a MySQL database
        /*
        'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=testdrive',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        ),
        */

        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),

        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                array(
                    'class' => 'CFileLogRoute',
                    'levels' => 'error, warning',
                ),
                // uncomment the following to show log messages on web pages
                /*
                array(
                'class'=>'CWebLogRoute',
                ),
                */
            ),
        ),
    ),

    'params' => array(
        // this is used in contact page
        'adminEmail' => 'webmaster@example.com',
    )

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
);


Dziękuję VIKTOR. Działa. Od razu robię kopię:) Dziękuję Ci serdecznie, dopiero się uczę:)
0

#8 User is offline   nineinchnick 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 622
  • Joined: 12-September 11
  • Location:Bialystok, Poland

Posted 06 June 2014 - 05:00 PM

Do poprawiania błędów składni używaj IDE a nie forum, to bardzo podstawowa czynność. Oszczędzisz dużo czasu.
Don't be a dick.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users