-# Search Engine Optimization CakePHP Plugin* Author: Saleh Souzanchi <http://soozanchi.ir> Lars Lenecke http://twitter.com/func0d3r* Version: 1.0.0* License: MIT* Website: <http://www.webtechnick.com>## Features* support multi language in form ( Model.fieldName.locale )* save and edit record , is very easy* validate all language for a field## Changelog* 1.0.0 first release.## InstallClone the MultiTranslateBehavior.php into your `app/Model/Behavior` directory:## Setup1-in model : <?php class Post extends AppModel{ public $actsAs = array( 'MultiTranslate' => array( 'title','body' ) ); public $validate = array( 'title' => array( 'rule' => 'notEmpty', 'message' => ' your message ' ), 'body' => array( 'rule' => 'notEmpty', 'message' => 'message' ), ); }2- in controller : <?php class PostsController extends AppController { public function admin_index() { $this->Post->setLocale( array( 'fa', 'en' ) ); $Results = $this->Paginator->paginate( 'Post' ); $this->set( 'Results', $Results ); } public function admin_add() { $this->Post->setLocale( array( 'fa', 'en' ) ); $this->Post->multiTranslateOptions( array( 'validate' => true ) ); if ( $this->request->is( 'post' ) ) { $this->Post->create(); if ( $this->Post->save( $this->request->data ) ) { $this->Irsa->IrsaFlashRedirect( __(' '), array( 'action' => 'index' ) ); } } } public function admin_edit( $id = null ) { $this->Post->setLocale( array( 'fa', 'en' ) ); $this->Post->id = $id; if ( !$this->Post->exists() ) { throw new NotFoundException( __( 'Invalid Post' ) ); } $this->Post->multiTranslateOptions( array( 'validate' => true, 'find' => true ) ); if ( $this->request->is( 'post' ) || $this->request->is( 'put' ) ) { if ( $this->Post->save( $this->request->data ) ) { $this->Irsa->IrsaFlashRedirect( __( ' ' ), array( 'action' => 'index' ) ); } else { $this->Irsa->IrsaFlash( __(' . .'), 'W' ); } } $this->request->data = $this->Post->read( null, $id ); } } ?> 3- in view/forms : <?php echo $this->Form->create('Post'); echo $this->Form->input('Post.title.eng'); echo $this->Form->input('Post.title.per'); echo $this->Form->input('Post.title.pol'); echo $this->Form->input('Post.body.eng'); echo $this->Form->input('Post.body.per'); echo $this->Form->input('Post.body.pol'); echo $this->Form->end('save'); ?>
0 commit comments