A
A
Actor2014-03-04 08:27:07
Yii
Actor, 2014-03-04 08:27:07

Yii/php: How to populate a custom template with data?

How can I fill in a letter template taken from the database with values?
For example, there is a template:
Hello, Friend!
Your uncle is writing you <%= $user->name %> etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mikitachu, 2014-03-05
@mikitachu

PHP itself is a template engine that solves your problem:
<?=$user->name?>

R
Roman Makarov, 2014-03-04
@vollossy

I would suggest using a ready made template engine like twig to render the template.

P
Pavel Tereshchenko, 2014-06-24
@l2ping

0. Create the AUser.php model:

<?php
class AUser extends CActiveRecord
{
    public $id, $login, $hash, $email;
    public $tel_1, $tel_2, $tel_3, $country_id;

    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    public function tableName(){
// Название таблицы с данными пользователей в БД
  return 'user';
    }
}

1. In the controller, we make a selection from the database by user id;
2. Pass data to the template:
3. Output data in the template:
<body>
<div>
Привет, <?=$userData['name']?>!
</div>
</body>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question