CodeIgniter Forums

Full Version: Fieldnames and templates rendering
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello All,
When you name table fields like this : id, date, action_id ...
in your template you have <tr><td>{id}</td><td>{date}</td><td>{action_id}</td>...

during variable replacement in template file, CI4 does
id -> {id} : OK
date -> {date} : OK 
but : id -> {id_action} : !OK

it works fine, if fields are named like this : id, date, action_id

Right ? 
Why ?
Thanks, nice day
Eric
Did not understand the issue. Please paste code example and your DB structure, that would include data types and how you extract data for template. Also, please specify CI4 version you are running, and your environment (Windows or Linux), also PHP version in use.
(03-14-2020, 03:27 AM)zahhar Wrote: [ -> ]Did not understand the issue. Please paste code example and your DB structure, that would include data types and how you extract data for template. Also, please specify CI4 version you are running, and your environment (Windows or Linux), also PHP version in use.
Thank you for your help

CREATE TABLE `wlt_transaction` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_action` int(11) NOT NULL,
  `date` date NOT NULL,
  `quantite` int(11) NOT NULL,
  `id_cours` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_action` (`id_action`),
  KEY `id_cours` (`id_cours`)
);

Controller
public function index(){

$model = new TransactionModel();
$data = ['transactions' => $model->getTransaction(),'title' => 'Liste des transactions',];
$parser = \Config\Services::parser();
$view = \Config\Services::renderer();
echo $view->render('templates/header');
echo $parser->setData($data)->render('transaction/index');
echo $view->render('templates/footer');
}

Model
class TransactionModel extends Model {

    protected $table = 'wlt_transaction';
    protected $primaryKey='id';

public function getTransaction($id = false){
if ($id === false) {
return $this->asArray()->orderBy('date', 'desc')->findAll();
} else return $this->asArray()->where(['id' => $id])->first();
}
View
<tbody>

    {transactions}
        <tr><td>{ date }</td><td>{ id_action }</td><td>{ quantite }</td><td>{id_cours}</td></tr>
    {/transactions}
</tbody>

HTML

[Image: Gcn8VxY]

CI version 4.0.2 (composer.lock)
PHP Version 7.2.24-0ubuntu0.18.04.3