Deve dar para herdar o ORM e só sobrescreever o metodo initialize ou fazer
um modulo, mas como estava com prazo curto... hehehe


2012/12/14 Rodrigo Monteiro Ferreira <[email protected]>

> Sem problemas, no meu caso eu precisei fazer assim... um banco de dados
> para login que informa host, database, usuario e senha:
>
> ao fazer login:
>
> public function action_login(){       
>               
> $usuario = ORM::Factory('users')->where("username", "=", 
> $_POST['username'])->where("password", "=", md5($_POST['password']))->find();
> $config = ORM::factory("configs", $usuario->id_alert);
>
> Session::instance()->set('config', $config);
>
> }
>
>
>
> coloquei em *application/classes/orm.php *o codigo:
>
> <?php defined('SYSPATH') or die('No direct script access.');
>
> class ORM extends Kohana_ORM {
>       
>       protected function _initialize()
>       {
>               // Set the object name and plural name
>               $this->_object_name = strtolower(substr(get_class($this), 6));
>               $this->_object_plural = Inflector::plural($this->_object_name);
>       
>               if ( ! $this->_errors_filename)
>               {
>                       $this->_errors_filename = $this->_object_name;
>               }
>       
>               if ( ! is_object($this->_db))
>               {
>                       if($this->_db_group == 'default') *// Se for Default 
> usa dados da session*
>                       {
>                               $this->_db = Database::instance('default', array
>                                               (
>                                                               'type'       => 
> 'mysql',
>                                                               'connection' => 
> array(
>                                                                               
> 'hostname'   => Session::instance()->get("config")->host,
>                                                                               
> 'database'   => Session::instance()->get("config")->database,
>                                                                               
> 'username'   => Session::instance()->get("config")->user,
>                                                                               
> 'password'   => Session::instance()->get("config")->password,
>                                                                               
> 'persistent' => FALSE,
>                                                               ),
>                                                               'table_prefix' 
> => '',
>                                                               'charset'      
> => 'utf8',
>                                                               'caching'      
> => FALSE,
>                                                               'profiling'    
> => TRUE,
>                                               ));
>                       }else{
>                               $this->_db = 
> Database::instance($this->_db_group); *// Se nao segue a mesma logica*
>                       }
>               }
>       
>               if (empty($this->_table_name))
>               {
>                       // Table name is the same as the object name
>                       $this->_table_name = $this->_object_name;
>       
>                       if ($this->_table_names_plural === TRUE)
>                       {
>                               // Make the table name plural
>                               $this->_table_name = 
> Inflector::plural($this->_table_name);
>                       }
>               }
>       
>               foreach ($this->_belongs_to as $alias => $details)
>               {
>                       $defaults['model'] = $alias;
>                       $defaults['foreign_key'] = 
> $alias.$this->_foreign_key_suffix;
>       
>                       $this->_belongs_to[$alias] = array_merge($defaults, 
> $details);
>               }
>       
>               foreach ($this->_has_one as $alias => $details)
>               {
>                       $defaults['model'] = $alias;
>                       $defaults['foreign_key'] = 
> $this->_object_name.$this->_foreign_key_suffix;
>       
>                       $this->_has_one[$alias] = array_merge($defaults, 
> $details);
>               }
>       
>               foreach ($this->_has_many as $alias => $details)
>               {
>                       $defaults['model'] = Inflector::singular($alias);
>                       $defaults['foreign_key'] = 
> $this->_object_name.$this->_foreign_key_suffix;
>                       $defaults['through'] = NULL;
>                       $defaults['far_key'] = 
> Inflector::singular($alias).$this->_foreign_key_suffix;
>       
>                       $this->_has_many[$alias] = array_merge($defaults, 
> $details);
>               }
>       
>               // Load column information
>               $this->reload_columns();
>       
>               // Clear initial model state
>               $this->clear();
>       }
>       
> }
>
> Entao os models que utilizarem o group default ira usar no ORM os dados da 
> session, no config/database.php os dados da config default podem ficar em 
> branco... se tiver duvida manda ai!
>
>
> Em 13 de dezembro de 2012 19:30, Erick Barbosa 
> <[email protected]>escreveu:
>
> eria pedir demais se você colocasse um um tutorial mais detalhada ou um
>> vídeo mostrando como fazer?
>>
>
>
>
> --
> Rodrigo Monteiro
> [email protected]
> (11) 96267-9366
>
>


-- 
Rodrigo Monteiro
[email protected]
(11) 96267-9366

-- 
Você está recebendo esta mensagem porque se inscreveu no grupo "Kohana Php" dos 
Grupos do Google.
Para postar neste grupo, envie um e-mail para [email protected].
Para cancelar a inscrição nesse grupo, envie um e-mail para 
[email protected].
Para obter mais opções, visite esse grupo em 
http://groups.google.com/group/kohana-php?hl=pt-BR.

Responder a