I am using the Smarty engine and I want to pass a Smarty variable to an object argument.
My index.php:
<?php
$smarty = new Smarty;
$smarty->registerObject('articles',$articles);
if (isset($_GET['task'])){
$smarty->assign('articleid',$_GET['id']);
}
My class for edit article:
public function editArticle($id) {
// database connection
$conn = parent::Db();
$q = $conn->prepare('SELECT * FROM articles WHERE id = :id ');
$q->execute(array(':id'=> $id ));
$results = $q->fetchAll(PDO::FETCH_ASSOC);
....
}
I want id for my function and my tpl:
{if isset($smarty.get.task) && $smarty.get.task eq articleedit}
<div class="box">
<div class="box-header"> <h3 class="box-title">Bordered Table</h3></div>
<div class="box-body">
{articles->editArticle p1=$articleid }
</div>
</div>
{/if}
How can I pass an argument to my object? I read the Smarty document and it suggested this line :
{articles->editArticle p1=$articleid }
but doesn't work for me.