Zendcasts Forum

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

You are not logged in.

#1 2010-06-23 20:18:16

bluesapphire
New member
Registered: 2010-06-23
Posts: 4

Doctrine's I18n in code

Hi!
    Kindly view following link:
http://www.sitepoint.com/forums/showthr … ost4627974

Can some one guide me what and where Iam doing wrong and how it can be rectified.

Thanks in advance

Offline

#2 2010-06-24 02:08:10

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

Re: Doctrine's I18n in code

Hi Bluesapphire,

first I'd like to welcome you to our humble little forum!

In terms of your question, what's the actual error you're getting? It looks like the i18n module is just building on the existing one-to-many architecture that Doctrine supports innately. Have you tried getting a simple one-to-many example working?

Offline

#3 2010-06-24 15:45:58

bluesapphire
New member
Registered: 2010-06-23
Posts: 4

Re: Doctrine's I18n in code

Thanks. Your casts are awasome and really inspired me to learn ZF.

I have following code in adition to previously mentioned code on sitepoint link:

Main Exam class:

<code>
class Model_Base_Exam extends Doctrine_Record  {

    public function  setTableDefinition() {
        $this->setTableName('exam');

        $this->option('type', 'INNODB');
        $this->option('charset', 'utf8');
        $this->option('collate', 'utf8_general_ci');


        $this->hasColumn('eid', 'integer', 11, array(
            'primary'  => true,
            'unsigned' => true,
            'notnull'  => true,
         ));
    }

    public function setUp(){
       
        $this->hasMany('Model_ExamTranslation as Translation', array(
            'local'      => 'eid',
            'foreign'    => 'etid',
            'onUpdate'   => 'CASCADE',
            'onDelete'   => 'RESTRICT',
            'owningSide' => false,
        ));


        $this->actAs('I18n', array(
                            'fields'     => array('title'),
                            'className'  => 'Model_ExamTranslation',
        ));
       

    }
}
?>

</code>

Exam Translation Class :

<code>
<?php
class Model_Base_ExamTranslation extends Doctrine_Record {

        public function setTableDefinition(){
            $this->setTableName('exam_translation');

            $this->option('type', 'INNODB');
            $this->option('charset', 'utf8');
            $this->option('collate', 'utf8_general_ci');

            $this->hasColumn('etid', 'integer', 11, array(
                'primary'  => true,
                'unsigned' => true,
                'notnull'  => true,
                ));
            $this->hasColumn('lang', 'string', 2, array(
                'primary'  => true,
                'notnull'  => true,
                ));


            $this->hasColumn('title', 'string', 1000);

            $this->hasColumn('created', 'Timestamp');
            $this->hasColumn('updated', 'Timestamp');

        }

        public function setUp(){

            $this->hasOne('Model_Exam', array(
                'local'       =>  'etid',
                'foreign'     =>  'eid',
                'owningSide'  =>  true,
            ));



            $this->actAs('Timestampable', array(
                                'created'  => array(
                                        'name'     => 'created',
                                    ),
                                 'updated' => array(
                                         'name'    =>  'updated'
                                 ),
            ));
        }
}
?>
</code>

Iam inserting data as follows:

<code>
$exam->Translation['en']->title = 'My English Title';
$exam->Translation['fr']->title = 'Fu Ku Ji Mun';
</code>

By running following statement:
<code>
print_r(print_r($exam->toArray()));
</code>

I get following array:
<code>


Array
(
    [eid] => 6
    [Translation] => Array
        (
            [en] => Array
                (
                    [etid] => 6
                    [lang] =>
                    [title] => My English Title
                    [created] =>
                    [updated] =>
                )

            [fr] => Array
                (
                    [etid] => 6
                    [lang] =>
                    [title] => Fu Ku Ji Mun
                    [created] =>
                    [updated] =>
                )

        )

)
</code>

The problem seems that  'lang' is not getting value.

Can I have guidance that what is going wrong in my code and how it can be rectified.

Thanks in advance

Offline

#4 2010-06-26 14:46:10

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

Re: Doctrine's I18n in code

Isn't the second lang property redundant?

Offline

#5 2010-06-30 16:14:17

bluesapphire
New member
Registered: 2010-06-23
Posts: 4

Re: Doctrine's I18n in code

Sorry I didn't get your point. Iam just trying to mimic database tables and other details from following link:

http://www.doctrine-project.org/project … viors:i18n

Thanks

Offline

Board footer

Powered by FluxBB