2010-12-05 54 views
0

我在学习Symfony,遇到了一个问题,我找不到答案: 我以Jobeet-1.4-Doctrine-恩。Symfony中的一个模块中的多个模型的数据

在3 day 3]天:这是所有关于模型,这我在哪里卡住 当生成的前端,在运行下面的命令:

$ PHP symfony的学说:生成模块--with -show --non-冗长的模板前端工作JobeetJob

它按照所提供的模块“JobeetJob”

我的问题生成模块“工作”,现在是:我有一个叫做“JobeetArticles另一个模块'人们可以在这里学习ñ如何写更好的简历等等。我希望'JobeetJob'和'JobeetArticles'中的数据都可用于“作业”模块。我怎么能做到这一点? 我希望我的问题是清楚的

问候

回答

1

一般来说,如果你的关系是设置正确(我不知道,如果你需要做的Symfony什么让这个)你只是做类似与类别Jobeet的教程...

在作业的actions.class.php文件中,你有executeIndex,并且它里面有$ this-> categories = JobeetCategoryPeer :: getWithJobs();

这是做什么找到模型JobeetCategoryPeer并调用该模型中的getWithJobs()函数,然后它将该数据返回到作业控制器发送到视图作为$类别。

所以,你会想要做类似的事情,所以在JobeetArticlesPeer创建一个函数返回所需的数据...

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

    return self::doSelect($criteria); 

} 

而在你JobeetJob actions.class.php文件里的类似

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

并且最后在indexSuccess.php的为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; ?> 

其中t帽子应该给你一个关于如何从其他模型访问数据的一般想法

相关问题