Search code examples
phpyiicode-duplication

Yii Framework Similar Function to POST and GET


can anyone convert this code into the yii framework?

file name: text.php

<form method='POST' action='index.php'>
<input type='text' name='name'>
<input type='submit' value='SUBMIT'>
</form>

then the text in the text will be viewed in the index.

file name: index.php

$text=$_POST['name'];
echo "$text";

Can anyone implement this code in Yii? and what is also the code used for using GET method , assuming that the index.php will be the controller and the text.php will be the view file

(what i am trying to achieve here is to pass the value of the textbox named as 'name' to the controller)?

can anyone help?


Solution

  • Yii form generation:

    <?= CHtml::beginForm( array("controller/action") ) ?>
    <?= CHtml::textField("name", "") ?>
    <?= CHtml::endForm() ?>
    

    Yii CHtml docs

    Also you need implement CModel or CForm class to validate form.