php - How to add a second language at a later time for internationalization? -


i have following schema:

<!-- language: lang-xml --> <table name="blog" phpname="blog">     <column name="id" type="integer" required="true" primarykey="true" autoincrement="true" />     <column name="title" phpname="title" type="varchar" size="100" required="true" />     <column name="short_link" phpname="shortlink" type="varchar" size="64" required="false" />     <column name="description" phpname="description" type="longvarchar" required="false" />     <column name="content" phpname="content" type="longvarchar" required="false" />     <column name="visibility" phpname="visibility" type="integer" default="-1" required="true" />      <behavior name="i18n">         <parameter name="i18n_columns" value="title, short_link, description, content" />     </behavior>     <behavior name="timestampable" />     <behavior name="soft_delete" />     <behavior name="versionable" /> </table>  <table name="blog_i18n" phpname="blogi18n">     <column name="id" type="integer" required="true" primarykey="true" />     <column name="locale" type="varchar" size="5" required="true" primarykey="true" />     <column name="title" phpname="title" type="varchar" size="100" required="false" />     <column name="short_link" phpname="shortlink" type="varchar" size="64" required="false" />     <column name="description" phpname="description" type="longvarchar" required="false" />     <column name="content" phpname="content" type="longvarchar" required="false" />      <foreign-key foreigntable="blog" ondelete="setnull" onupdate="cascade">         <reference local="id" foreign="id" />     </foreign-key>      <behavior name="timestampable" />     <behavior name="soft_delete" />     <behavior name="versionable" /> </table> 

when add new post, adds single language(main app language), idea leave option more languages @ later time.

this code adds post:

<!-- language: lang-php --> public function addblogpost(application $app) {      $data = array (         'title' => $app['request']->get('title'),         'language' => $app['request']->get('language'),         'short-link' => $this->createshortlink($app, $app['request']->get('title')),         'description' => $app['request']->get('description'),         'content' => $app['request']->get('content')         );      $blog = new blog();      $blog->setlocale($data['language']);     $blog->settitle($data['title']);     $blog->setshortlink($data['short-link']);     $blog->setdescription($data['description']);     $blog->setcontent($data['content']);      try {         $blog->save();         $app['session']->getflashbag()->add(             'success',             'success_add_blog_text'            );             return $app->redirect($app['url_generator']->generate('adminblog'));     } catch (propelexception $pe) {         $app['session']->getflashbag()->add(             'error',             'error_add_blog_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     } } 

up until here works beautifully expected, when try perform edit, on whatever language, doesnt work.

<!-- language: lang-php --> public function editblogpost(application $app) {     $id = $app['request']->get('id');     $lang = $app['request']->get('language');     if(!is_numeric($id)) {         $app['session']->getflashbag()->add(                 'error',                 'blog_doesnt_exists_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     }      $data = array (         'id' => $app['request']->get('id'),         'language' => $app['request']->get('language'),         'title' => $app['request']->get('title'),         'short-link' => $app['request']->get('short-link'),         'description' => $app['request']->get('description'),         'content' => $app['request']->get('content')         );      $post = blogquery::create();      $post->setlocale($data['language']);     $post->settitle($data['title']);     $post->setshortlink($data['short-link']);     $post->setdescription($data['description']);     $post->setcontent($data['content']);      try {         $post->save();         $app['session']->getflashbag()->add(             'success',             'success_edit_blog_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     } catch (propelexception $pe) {         $app['session']->getflashbag()->add(             'error',             'error_edit_blog_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     } } 

error 500.

undefined method modelcriteria::setlocale()

is get. should edit using blogl18nquery instead? or doing wrong way get-go?

ok after testing (due lack of perform complex searches answers have admit)

this did , works (it may not best solution tho, works now).

<!-- language: lang-php --> public function editblogpost(application $app) {     $id = $app['request']->get('id');     $lang = $app['request']->get('language');     if(!is_numeric($id)) {         $app['session']->getflashbag()->add(                 'error',                 'blog_doesnt_exists_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     }      // check if item exists, if doesnt, error.     $blog = blogquery::create()         ->filterbyid($id)         ->count();     if($blog<1) {         $app['session']->getflashbag()->add(             'error',             'blog_doesnt_exists_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     }      $data = array (         'id' => $app['request']->get('id'),         'language' => $app['request']->get('language'),         'title' => $app['request']->get('title'),         'short-link' => $app['request']->get('shortlink'),         'description' => $app['request']->get('description'),         'content' => $app['request']->get('content')         );      $post = new blogi18n();     $post->setid($data['id']);     $post->setlocale($data['language']);     $post->settitle($data['title']);     $post->setshortlink($data['short-link']);     $post->setdescription($data['description']);     $post->setcontent($data['content']);      try {         $post->save();         $app['session']->getflashbag()->add(             'success',             'success_edit_blog_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     } catch (propelexception $pe) {         $app['session']->getflashbag()->add(             'error',             'error_edit_blog_text'             );         return $app->redirect($app['url_generator']->generate('adminblog'));     }  } 

i went usage of blogi18n , did trick.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -