Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2009-12-29 03:49:40

Jon Lebensold
Administrator
Registered: 2009-06-27
Posts: 279

ZC41 – Doctrine Relations and Zend MVC

Happy Holidays everyone!

This short podcast covers how you can easily build a form using Zend's MVC model via Zend_Controller and using Doctrine for persistence.

You can download the source code or browse it online. Enjoy!

zend_controller, mvc, doctrine, relations, orm

Offline

#2 2009-12-30 02:59:23

harri
Member
From: Kristiansand, Norway
Registered: 2009-12-02
Posts: 27
Website

Re: ZC41 – Doctrine Relations and Zend MVC

Awesome stuff!
Finaly a example of how to use the stuff we've learned.:)

I see you don't use Zend Form. I guess its to make the example a little simpler. Is it much more difficult to use Zend Form than the way you did here? There must surely be some advantages with using Zend Form?

Offline

#3 2011-06-07 15:47:01

miguelp
New member
From: Portugal
Registered: 2010-05-11
Posts: 8
Website

Re: ZC41 – Doctrine Relations and Zend MVC

Hi,

I followed this tutorial but still i have some questions, here is my example:

Yaml:
Core_Model_Language:
  connection: default
  tableName: core_language
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    short:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    active:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    News_Model_Noticias:
      local: id
      foreign: lang_id
      type: many
News_Model_Noticias:
  connection: default
  tableName: news_noticias
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    titulo:
      type: string(250)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    small:
      type: string(400)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    full:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    data_creation:
      type: timestamp(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    published:
      type: integer(1)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false
    lang_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    Core_Model_Language:
      local: lang_id
      foreign: id
      type: one

Ok so i have this 2 tables (Models), i want to load all news and when presenting the list show the language name for that news item.

in my action i have:
public function indexAction()
    {
        $model = Doctrine::getTable('News_Model_Noticias');
        $noticias = $model->findAll();
        $this->view->noticias = $noticias;
    }

Now if i vardump($this->noticias) on my view i get something like this:
array(1) {
  [0] => array(7) {
    ["id"] => string(1) "4"
    ["titulo"] => string(5) "teste"
    ["small"] => string(24) "teste introdução noticia"
    ["full"] => string(18) "Montes de conteudo"
    ["data_creation"] => string(19) "0000-00-00 00:00:00"
    ["published"] => string(1) "0"
    ["lang_id"] => string(1) "1"
  }
}

Is there an easy way i can get the relation data automaticly? something like:
array(1) {
  [0] => array(7) {
    ["id"] => string(1) "4"
    ["titulo"] => string(5) "teste"
    ["small"] => string(24) "teste introdução noticia"
    ["full"] => string(18) "Montes de conteudo"
    ["data_creation"] => string(19) "0000-00-00 00:00:00"
    ["published"] => string(1) "0"
    ["language"] => array(4){
        ["id"] => string(1) "1"
        ["name"] => string(9) "Português"
        ["short"] => string(5) "pt_PT"
        ["active"] => string(1) "1"
    }
  }
}

If i vardump language model i get the news related to that language, but i wanna do it the other way around, fetch the news and have it grab the language object for each news item in an automated way, without having to write all the Joins by hand, since the languages table is related to pretty much all the other tables in my app.

Thanks in advance

Last edited by miguelp (2011-06-07 15:47:41)

Offline

Board footer

Powered by FluxBB