cymbals
(Brent Hathaway)
April 14, 2015, 2:20pm
1
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?
cymbals:
and my url that I am trying is:
localhost/basic/index.php?r=site/say&message=Hello+World
ps: localhost/basic/web/index.php works fine
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
cymbals
(Brent Hathaway)
April 15, 2015, 1:58pm
4
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
cymbals
(Brent Hathaway)
April 15, 2015, 2:56pm
6
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' => [
'class' => AccessControl::className(),
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionIndex()
{
return $this->render('index');
}
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
public function actionAbout()
{
return $this->render('about');
}
public function actionSay($message = 'Hello')
{
return $this->render('say', ['message' => $message]);
}
}
cymbals
(Brent Hathaway)
April 15, 2015, 2:57pm
7
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); ?>
cymbals
(Brent Hathaway)
April 17, 2015, 7:02pm
9
Ah, the shorthand method - wasn’t familiar with the =. Thanks!