Add a very simple todolist

Hello,

I’ve a very simple chat that’s working.

There’s 2 files.

I add this one on the about page of the basic app Yii :





<?php

setlocale(LC_TIME, 'fr_FR');

$date = strftime('%d/%m/%Y %H:%M:%S');

echo "Nous somme le : $date";


$today = date("Y-m-d H:i:s");

?>   

<center>

<form action="cible.php" method="post">

<p>

    <label for="pseudo">Pseudo</label> : <input type="text" name="pseudo" /><br />

    <label for="message">Message</label> : <input type="text" name="message"/><br />

    <input type="hidden" name="date" value="<?php echo $today ?>" />

    <input type="submit" value="Valider" />

</p>

</form>


</center>


<?php

try

{

    $bdd = new PDO('mysql:host=localhost;dbname=chat', 'user', 'pwd');

}

catch(Exception $e)

{

        die('Erreur : '.$e->getMessage());

}


$reponse = $bdd->query('SELECT pseudo, message, date FROM minichat ORDER BY date DESC LIMIT 10');

while ($donnees = $reponse->fetch())

{

    echo '<p><strong>' . htmlspecialchars($donnees['pseudo']) . '</strong> : ' . htmlspecialchars($donnees['message']) . htmlspecialchars($donnees['date']) . '</p>';

}

$reponse->closeCursor();

?>




And this one is on the views directory :





<?php

try

{

    $bdd = new PDO('mysql:host=localhost;dbname=chat', 'user', 'pwd');

}

catch(Exception $e)

{

        die('Erreur : '.$e->getMessage());

}


$req = $bdd->prepare('INSERT INTO minichat (pseudo, message, date) VALUES(?, ?, ?)');

$req->execute(array($_POST['pseudo'], $_POST['message'], $_POST['date']));




header('Location: about.php');

?>




I add this to the controller :





public function actionCible()

    {

        return $this->render('cible');

    }




But I have a 404 error when I submit the form.

I don’t understand why.

If someone could help please ?

Cordially,

ANDRE Ani

Hey,

Sorry if this is not your expected answer but:

To me it looks like you have not understand even the basics.

My advice when looking at your code:

To improve your overall technique…

You should SERIOUSLY read and understand the guide first.

Read it from beginning to end… and read every single topic.

http://www.yiiframework.com/doc-2.0/guide-README.html

Best Regards

I’m reading it. I want to learn, I’m beginning.

Could you explain me what I misunderstand please ?

It’s a framework for help devs to make application. Surely I make it the wrong way.

For the first step, use Gii to generate an ActiveRecord model for your ‘minichat’ table.

And the second step is to create CRUD pages for the model, also using Gii.

It may look overdoing for a simple chat at a first glance, but you’ll surely learn what it is like to work with a framework.

It doesn’t require much knowledge, just read the “Getting Started” sections of the guide.

Thanks for the help :wink: