• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fieldnames and templates rendering

#3
(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
Reply


Messages In This Thread
Fieldnames and templates rendering - by foxbille - 03-14-2020, 02:09 AM
RE: Fieldnames and templates rendering - by foxbille - 03-14-2020, 06:55 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.