0
votes

I'm learning Symfony and I came across one issue and I couldn't find an answer: I'm taking as an example the Jobeet tutorial from Jobeet-1.4-Doctrine-en.

On day 3 [ day 3 ]: It's all about the model and this where I am stuck When generating the frontend, the following command is run:

$ php symfony doctrine:generate-module --with-show --non-verbose-templates frontend job JobeetJob

It generates the module 'job' in accordance with the provided module 'JobeetJob'

My question now is: I have an another module called 'JobeetArticles' where people can learn how to write better CV and such things. I want to have both data from 'JobeetJob' and 'JobeetArticles' available for the 'job' module. How can i accomplish that? I hope my question is clear

Regards

1

1 Answers

1
votes

Generally if your relationships are setup correctly (I'm not sure if you NEED to do anything in Symfony to allow this) you would just do something like in the jobeet tutorials with categories...

in the actions.class.php file for job you have executeIndex and inside of it you have $this->categories = JobeetCategoryPeer::getWithJobs();

and what this is doing is finding the model JobeetCategoryPeer and calling the getWithJobs() function in that model and then it returns that data back to the job controller to send to the view as $categories.

So you would want to do something similar, so in JobeetArticlesPeer create a function to return the data you want...

static public function getArticles()
{
  $criteria = new Criteria();
  //whatever criteria you want in here

  return self::doSelect($criteria);  

}

And in your JobeetJob actions.class.php file something like

public function executeIndex(sfWebRequest $request)
{
  $this->articles = JobeetArticlesPeer::getArticles();
}

And lastly in your indexSuccess.php for JobeetJob

<?php foreach ($articles as $article): ?>
  <div class="article">
    <div class="article_title">
      <h1>
        <?php echo link_to($article, 'article', $article) ?>
      </h1>
      <?php echo $article->getAuthor() //field name for author ?>
    </div>
    <div class="article_content">
      <?php echo $article->getContent() //field name for article content ?>
    </div>
  </div>
<?php endforeach; ?>

And that should give you a general idea of how to access data from other models