Unable to Assign $issueDao to Template

I have object of $issueDao:
$issueDao =& DAORegistry::getDAO(‘IssueDAO’);

I assign it to a template:
$templateMgr->assign_by_ref(‘issueDao’, $issueDao);

But, at the template, $issueDao doesn’t work.
How can I assign $issueDao to template successfully?

Hi @OJSUSER11,

I don’t see anything wrong with what you’re describing, so I think the problem must be elsewhere – maybe you’re editing the wrong class file, or template file, or the template cache file permissions are wrong and Smarty can’t recompile the template?

I think it’s generally not a good pattern to perform DAO operations in the template file, though; if you can describe what you’re working on in more detail maybe I can suggest an alternative.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks for your answer.

My goal is this: Having articleId on template side, I want to find the issueId where the article published in. Then using the issueId I wanted to display all (or some) of the articles published in that issue.

But, I cannot find any method on template side that can find the associate issueId having the articleId.

Just in back side in class I can see this method:

$foundIssue= $issueDao->getIssueByArticleId(articleId, $journalId = null)
& $publishedArticleDao->getPublishedArticlesInSections($foundIssue->getId(), true)

But I want to have such reverse operation methods in template side because I just have access to my articleId on template side.

Thanks for your answered. It works now.

Hi @OJSUSER11,

Glad it’s working! As for avoiding the use of the IssueDAO in the template, all you would need to do is use the IssueDAO in your Handler class to fetch the issue that the article appears in, fetch the list of articles, and assign that to the template (instead of the DAO). This would keep the logic in the PHP code and leave the presentation to the template.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like