[Solar-talk] Verifying Login Status
Antti Holvikari
anttih at gmail.com
Wed Feb 6 23:58:21 CST 2008
On Feb 7, 2008 12:52 AM, Sean Montague <scene at themountainscene.com> wrote:
>
> Thanks Rodrigo,
>
> You say that it would be better to set the auth adapter configuration in
> the config file. Which makes sense to me, so now I'm trying to figure out
> the best way to do this. My modified Solar.config.php looks like this:
>
> $config['Solar_Sql'] = array(
> 'adapter' => 'Solar_Sql_Adapter_Mysql',
> 'host' => 'localhost',
> 'user' => 'root',
> 'pass' => 'mypass',
> 'name' => 'mydb'
> );
>
> $sql = Solar::factory('Solar_Sql', $config['Solar_Sql']);
> $config['Solar_Sql'] = array(
> 'sql' => $sql,
> 'adapter' => 'Solar_Auth_Adapter_Sql',
> 'table' => 'users',
> 'handle_col' => 'username',
> 'passwd_col' => 'password',
> 'uid_col' => 'id',
> 'process_login' => 'submit login'
> );
> ...
>
> My Login.php is looks like:
>
> $sql = solar::factory('solar_sql');
> $sql->_config['adapter'] = 'Solar_Auth_Adapter_Sql';
> $auth = Solar::factory('Solar_Auth', $sql->_config);
> $auth->start();
> ....
Make sure $auth->start() gets called in *every* request. What you
should do is register a user object in your _setup() method within
your app class.
protected function _setup()
{
// register a Solar_Sql object if not already
if (! Solar_Registry::exists('sql')) {
Solar_Registry::set('sql', Solar::factory('Solar_Sql'));
}
// register a Solar_User object if not already.
// this will trigger the authentication process.
if (! Solar_Registry::exists('user')) {
Solar_Registry::set('user', Solar::factory('Solar_User'));
}
}
After that you can forget about your code above. This is because when
you factory() a user object it instantiates an auth object and calls
start() on it for you. Even better, if you are extending
Solar_App_Base, you see that it has exactly the same code as above in
_setup(). This means your can forget about my code too and everything
should work.
> In the config file, having "'adapter'=>'Solar_Auth_Adapter_Sql'" or
> "'adapter'=>'Solar_Sql_Adapter_Mysql'" makes no difference, they could just
> as easily be deleted. I need to set them in the Login.php script or the
> example I'm working with in Index.php, which looks like this:
>
> $sql = solar::factory('solar_sql');
> $sql->_config['adapter'] = 'Solar_Sql_Adapter_Mysql';
> $select = Solar::factory('Solar_Sql_Select', $sql->_config);
> $select->from('users',array('*'));
> ....
I not exactly sure what you are trying to do here but
$sql->_config['adapter'] will have no effect because
Solar_Sql_Adapter::_config is a protected class property. The good
news is that you don't need to do anything like that. Remember in the
_setup() code I gave you, it registers an sql object for you too. This
means all the Solar_Sql_* classes will use it now. So all you have to
do is:
$select = Solar::factory('Solar_Sql_Select');
$select->from('users',array('*'));
--
Antti Holvikari <http://anttih.com>
More information about the Solar-talk
mailing list