404 on Hello World

Hi,

I am following the instructions at:

doc-2.0/guide-start-hello.html

and my url that I am trying is:

localhost/basic/index.php?r=site/say&message=Hello+World

WAMP is running fine. Do I need an .htaccess somewhere? What am I missing please?

Thanks.

ps: localhost/basic/web/index.php works fine

Do you see the Yii generated 404 page or the one from your wamp server?

Is it possible that you use the wrong path in your url?

In your first link you try to open:

localhost/basic/index.php?r=site/say&message=Hello+World

In your second link you try to open:

localhost/basic/web/index.php

Try: localhost/basic/web/index.php?r=site/say&message=Hello+World

  1. I see the wamp (apache) 404.

  2. I am using the url in docs. I have multiple sites in wamp, but I am just using subfolders (no code is depending on /). I will try creating virtual hosts and get back to you further.

  3. I tried that idea - the application comes up, but no Hello World message.

Update: I moved everything to the root, but the same problem exists.

If I use localhost/web/index.php?r=site/say&message=Hello+World I get an application page but no message.

If I use http://localhost/index.php?r=site/say&message=Hello+World like the docs say, I get an 404.

Any ideas?

Without any additional .htaccess or virtual host configuration the path should be:

localhost/yourProjectFolder/web/index.php?r=site/say&message=Hello+World

Please post the content of your:

app/constrollers/SiteController.php

app/views/site/say.php

I’m sure you have mistake somewhere.

Also: Do the other things work?

Like the "About" Page?

If yes - you could analyze its code to get a better understanding.

Regards

Thanks for responding. The about page does work.

views/site/say.php:

<?php

use yii\helpers\Html;

?>

<? Html::encode($message); ?>


controllers/SiteController.php:

<?php

namespace app\controllers;

use Yii;

use yii\filters\AccessControl;

use yii\web\Controller;

use yii\filters\VerbFilter;

use app\models\LoginForm;

use app\models\ContactForm;

class SiteController extends Controller

{

public function behaviors()


{


    return [


        'access' =&gt; [


            'class' =&gt; AccessControl::className(),


            'only' =&gt; ['logout'],


            'rules' =&gt; [


                [


                    'actions' =&gt; ['logout'],


                    'allow' =&gt; true,


                    'roles' =&gt; ['@'],


                ],


            ],


        ],


        'verbs' =&gt; [


            'class' =&gt; VerbFilter::className(),


            'actions' =&gt; [


                'logout' =&gt; ['post'],


            ],


        ],


    ];


}





public function actions()


{


    return [


        'error' =&gt; [


            'class' =&gt; 'yii&#092;web&#092;ErrorAction',


        ],


        'captcha' =&gt; [


            'class' =&gt; 'yii&#092;captcha&#092;CaptchaAction',


            'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,


        ],


    ];


}





public function actionIndex()


{


    return &#036;this-&gt;render('index');


}





public function actionLogin()


{


    if (&#33;&#092;Yii::&#036;app-&gt;user-&gt;isGuest) {


        return &#036;this-&gt;goHome();


    }





    &#036;model = new LoginForm();


    if (&#036;model-&gt;load(Yii::&#036;app-&gt;request-&gt;post()) &amp;&amp; &#036;model-&gt;login()) {


        return &#036;this-&gt;goBack();


    } else {


        return &#036;this-&gt;render('login', [


            'model' =&gt; &#036;model,


        ]);


    }


}





public function actionLogout()


{


    Yii::&#036;app-&gt;user-&gt;logout();





    return &#036;this-&gt;goHome();


}





public function actionContact()


{


    &#036;model = new ContactForm();


    if (&#036;model-&gt;load(Yii::&#036;app-&gt;request-&gt;post()) &amp;&amp; &#036;model-&gt;contact(Yii::&#036;app-&gt;params['adminEmail'])) {


        Yii::&#036;app-&gt;session-&gt;setFlash('contactFormSubmitted');





        return &#036;this-&gt;refresh();


    } else {


        return &#036;this-&gt;render('contact', [


            'model' =&gt; &#036;model,


        ]);


    }


}





public function actionAbout()


{


    return &#036;this-&gt;render('about');


}





public function actionSay(&#036;message = 'Hello')


{


return &#036;this-&gt;render('say', ['message' =&gt; &#036;message]);


}

}

Ack the formatting got all screwed up - sorry.

The Problem is here:

in app/views/site/say.php you have:




<? Html::encode($message); ?>



That should be:

<?[color="#FF0000"]=[/color] Html::encode($message); ?>

OR

<?php [color="#FF0000"]echo[/color] Html::encode($message); ?>

Ah, the shorthand method - wasn’t familiar with the =. Thanks!