本文整理汇总了PHP中Doctrine::getConnectionByTableName方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine::getConnectionByTableName方法的具体用法?PHP Doctrine::getConnectionByTableName怎么用?PHP Doctrine::getConnectionByTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine
的用法示例。
在下文中一共展示了Doctrine::getConnectionByTableName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signIn
public static function signIn($userName, $password, $rememberMe = false, $md5 = true)
{
$retVal = false;
// set ZendX_Doctrine_Auth_Adapter
$auth = Zend_Auth::getInstance();
$authAdapter = new ZendX_Doctrine_Auth_Adapter(Doctrine::getConnectionByTableName('Model_Entity_User'));
$password = $md5 ? md5($password) : $password;
$authAdapter->setTableName('Model_Entity_User u')->setIdentityColumn('userName')->setCredentialColumn('password')->setCredentialTreatment('? AND active = 1')->setIdentity($userName)->setCredential($password);
// set Zend_Auth
$result = $auth->authenticate($authAdapter);
// Check Auth Validation
if ($result->isValid()) {
// Remove some fields which are secure!
$omitColumns = array('password', 'activationKey', 'created_at', 'updated_at', 'deleted_at', 'created_by', 'updated_by');
$identity = $authAdapter->getResultRowObject(null, $omitColumns);
$identity->roles = Kebab_Model_User::getUserRoles($identity->id);
$identity->acl = new Kebab_Access_Acl();
$identity->stories = Kebab_Model_Story::getUserStoriesName($identity->roles);
$auth->getStorage()->write($identity);
if ($rememberMe) {
Zend_Session::rememberMe(604800);
}
$retVal = true;
}
return $retVal;
}
示例2: postSave
public function postSave($evt = null)
{
Doctrine::getConnectionByTableName($this->getTable()->getTableName())->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, false);
// we do not want to refresh our records
$this->updateLuceneIndex();
Doctrine::getConnectionByTableName($this->getTable()->getTableName())->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, true);
}
示例3: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
sfContext::createInstance($this->configuration);
$displayName = $this->ask("Enter a minyan display name (Darchei Noam Glenbrook)");
$identifier = $this->ask("Enter minyan identifier (dng)");
$email = $this->ask("Enter username for minyan admin");
$user = Doctrine::getTable('SfGuardUser')->findOneByUsername(trim(strtolower($email)));
if (!$user) {
throw new Exception("User with email {$email} does not exist");
}
try {
$con = Doctrine::getConnectionByTableName("SfGuardUser");
$con->beginTransaction();
$minyan = new Minyan();
$minyan->setName($displayName);
$minyan->setIdentifier(Utils::formatPermalink($identifier));
$minyan->save();
$minyanUser = new MinyanUser();
$minyanUser->setIsAdmin(true);
$minyanUser->setUserId($user->getId());
$minyanUser->setMinyanId($minyan->getId());
$minyanUser->save();
$this->logSection('mam', "Minyan {$identifier} created successfully!");
$con->commit();
} catch (Exception $e) {
$con->rollback();
throw $e;
}
}
示例4: preSave
public function preSave($evt = null)
{
Doctrine::getConnectionByTableName($this->getTable()->getTableName())->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, false);
// we do not want to refresh our records
$this->updateSlug();
Doctrine::getConnectionByTableName($this->getTable()->getTableName())->setAttribute(Doctrine_Core::ATTR_HYDRATE_OVERWRITE, true);
return parent::preSave($evt);
}
示例5: executeAddNewSubscriber
public function executeAddNewSubscriber(sfWebRequest $request)
{
$this->minyan = Utils::extractDomainObjectFromRequest($request, 'Minyan', 'minyanId', true);
$this->form = new SignupForm();
unset($this->form['password']);
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('signup'));
if ($this->form->isValid()) {
$fields = $this->form->getValues();
$con = Doctrine::getConnectionByTableName('SfGuardUser');
try {
$con->beginTransaction();
$this->logMessage("Executing signup for new user for minyan {$this->minyan->getName()}: {$fields['email']}", 'notice');
$sgu = new SfGuardUser();
$sgu->setFirstName($fields['first_name']);
$sgu->setLastName($fields['last_name']);
$sgu->setUsername($fields['email']);
$sgu->setEmailAddress($fields['email']);
$sgu->setPhone($fields['phone']);
$sgu->setPassword(sfConfig::get('app_temp_password'));
$sgu->setIsActive(true);
$sgu->save();
$contactMethods = $request->getParameter('contact_method');
foreach ($contactMethods as $name => $method) {
$contactMethods[$name] = Utils::toBoolean($method);
}
$minyanUser = new MinyanUser();
$minyanUser->setMinyanId($this->minyan->getId());
$minyanUser->setUserId($sgu->getId());
$minyanUser->setUsePhone($contactMethods['phone']);
$minyanUser->setUseSms($contactMethods['text']);
$minyanUser->setUseEmail($contactMethods['email']);
$minyanUser->save();
$con->commit();
} catch (Exception $e) {
$con->rollback();
$this->logMessage("Problem when signing up user {$fields['email']}: {$e->getMessage()}", 'notice');
throw $e;
}
MAMUtils::sendInternalEmail("New Make a Minyan User Alert for minyan {$this->minyan->getName()}! - {$sgu->getFullName()}", "");
//send email
$options = array();
$options['template'] = 'welcomeToMinyan';
$options['subject'] = 'Welcome!';
$options['minyan'] = $this->minyan;
$options['user'] = $sgu;
$options['minyanUser'] = $minyanUser;
$options['first_name'] = $sgu->getFirstName();
$options['to'] = $sgu->getUsername();
EmailUtils::send($options);
$this->logMessage('Welcome email sent to ' . $sgu->getUsername(), 'notice');
$this->getUser()->setFlash('subscribersSuccess', 'Added ' . $sgu->getUsername() . ' successfully!');
echo Utils::ajaxResponse(true, $this->minyan->getId());
return sfView::NONE;
}
}
}
示例6: getScheduleBirthMember
private static function getScheduleBirthMember(array $months, $day = null, $is_setKeydate = true)
{
$memberId = self::getMyId();
if (is_null(self::$birth_prof_id)) {
$profile = Doctrine::getTable('Profile')->createQuery()->select('id')->where('name = ?', 'op_preset_birthday')->fetchOne(array(), Doctrine::HYDRATE_NONE);
if (!$profile) {
return array();
}
self::$birth_prof_id = $profile[0];
}
if (is_null(self::$friendIds)) {
self::$friendIds = Doctrine::getTable('MemberRelationship')->getFriendMemberIds($memberId);
self::$friendIds[] = $memberId;
}
$q = Doctrine::getTable('MemberProfile')->createQuery()->select('member_id, value_datetime, public_flag')->where('profile_id = ?', self::$birth_prof_id)->andWhereIn('member_id', self::$friendIds);
$driverName = Doctrine::getConnectionByTableName('MemberProfile')->getDriverName();
foreach ($months as $month) {
$targetDate = $day ? sprintf('%02d-%02d', (int) $month, (int) $day) : sprintf('%02d', (int) $month);
if ($driverName === 'Sqlite') {
$targetValue = array($day ? '%m-%d' : '%m', $targetDate);
$q->andWhere('strftime(?, value_datetime) = ?', $targetValue);
} else {
if ($driverName === 'Pgsql') {
$targetValue = array($day ? 'MM-DD' : 'MM', $targetDate);
$q->andWhere('to_char(value_datetime, ?) = ?', $targetValue);
} else {
$targetValue = array($day ? '%m-%d' : '%m', $targetDate);
$q->andWhere('DATE_FORMAT(value_datetime, ?) = ?', $targetValue);
}
}
}
$birthResults = $q->execute(array(), Doctrine::HYDRATE_NONE);
if (!count($birthResults)) {
return array();
}
$results = array();
foreach ($birthResults as $birthResult) {
if ($memberId != $birthResult[0] && ProfileTable::PUBLIC_FLAG_PRIVATE == $birthResult[2]) {
continue;
}
$member = Doctrine::getTable('Member')->find($birthResult[0]);
if ($is_setKeydate) {
$results[substr($birthResult[1], 5, 5)][] = $member;
} else {
$results[] = $member;
}
}
return $results;
}
示例7: setLogin
public static function setLogin($username = '', $pasword = '')
{
$authAdapter = new Zend_Auth_Adapter_Doctrine_Table(Doctrine::getConnectionByTableName('Members'));
$authAdapter->setTableName('Members')->setIdentityColumn('username')->setCredentialColumn('password')->setCredentialTreatment('md5(?)')->setIdentity($username)->setCredential($pasword);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
$data = $authAdapter->getResultRowObject('username', 'password');
$auth->getStorage()->write($data);
$Member = Members::getByUsername($auth->getIdentity()->username);
$Member->log('Signed in', 'Members');
return $Member;
} else {
return false;
}
}
示例8: createUser
/**
* Create a user for a Facebook account
*
* Based on and borrowed heavily from
* sfFacebookGuardAdapter::createSfGuardUserWithFacebookUidAndCon in
* sfFacebookConnectPlugin by Fabrice Bernhard
*
* @param int $facebookUid
* @param string $accessToken
* @param int $accessTokenExpiry
* @param array $facebookUserInfo
* @return sfGuardUser
*/
public static function createUser($facebookUid, $accessToken, $accessTokenExpiry, array $facebookUserInfo)
{
$sfGuardUser = new sfGuardUser();
$sfGuardUser->setUsername(self::generateFacebookUsername($facebookUid));
$connection = Doctrine::getConnectionByTableName('sfGuardUser');
try {
$connection->beginTransaction();
$sfGuardUser->save();
$sfGuardUser->getProfile()->setFacebookOnlyAccount(true)->_connectToFacebook($facebookUid, $accessToken, $accessTokenExpiry, $facebookUserInfo, $sfGuardUser);
$connection->commit();
} catch (Exception $e) {
$connection->rollback();
throw $e;
}
return $sfGuardUser;
}
开发者ID:passkey1510,项目名称:sfFacebookGraphPlugin,代码行数:29,代码来源:PluginsfFacebookGraphUserProfile.class.php
示例9: executeIndex
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
$this->form = new SignupForm();
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('signup'));
if ($this->form->isValid()) {
$fields = $this->form->getValues();
$con = Doctrine::getConnectionByTableName('SfGuardUser');
try {
$con->beginTransaction();
$this->logMessage("Executing signup for new user: {$fields['email']}", 'notice');
$sgu = new SfGuardUser();
$sgu->setFirstName($fields['first_name']);
$sgu->setLastName($fields['last_name']);
$sgu->setUsername($fields['email']);
$sgu->setEmailAddress($fields['email']);
$sgu->setPhone($fields['phone']);
$sgu->setPassword($fields['password']);
$sgu->setIsActive(true);
$sgu->save();
$con->commit();
} catch (Exception $e) {
$con->rollback();
$this->logMessage("Problem when signing up user {$fields['email']}: {$e->getMessage()}", 'notice');
throw $e;
}
MAMUtils::sendInternalEmail("New Make a Minyan User Alert! - {$sgu->getFullName()}, Plan: {$this->plan['name']}", "");
//send email
$options = array();
$options['template'] = 'welcome';
$options['subject'] = 'Welcome!';
$options['first_name'] = $sgu->getFirstName();
$options['to'] = $sgu->getUsername();
EmailUtils::send($options);
$this->logMessage('Welcome email sent to ' . $sgu->getUsername(), 'notice');
$this->redirect('signup/thanks');
}
}
}
示例10: dirname
<?php
$app = 'frontend';
include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php';
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$databaseManager = new sfDatabaseManager($configuration);
$con = Doctrine::getConnectionByTableName('sfAsset');
$con->beginTransaction();
try {
// prepare test environment
sfAssetFolderTable::getInstance()->createQuery()->delete()->execute();
sfAssetTable::getInstance()->createQuery()->delete()->execute();
sfConfig::set('app_sfAssetsLibrary_upload_dir', 'mediaTEST');
$root = new sfAssetFolder();
$root->setName(sfConfig::get('app_sfAssetsLibrary_upload_dir'));
$tree = sfAssetFolderTable::getInstance()->getTree();
$tree->createRoot($root);
$root->save();
// run the tests
$t = new lime_test(23, array('options' => new lime_output_color(), 'error_reporting' => true));
$t->diag('sfAsset');
$sfAsset = new sfAsset();
$sfAsset->setFolder($root);
$t->isa_ok($sfAsset->getFolder(), 'sfAssetFolder', 'sfAsset can have root as folder');
$sfAsset->setFilename('filename.jpg');
$t->diag('sfAsset::getRelativePath()');
$t->is($sfAsset->getRelativePath(), sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getRelativePath() returns the path relative to the media directory');
$t->diag('sfAsset::getFullPath()');
$t->is($sfAsset->getFullPath(), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'filename.jpg', 'getFullPath() returns the complete asset path on the disk');
$t->is($sfAsset->getFullPath('small'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . 'small_filename.jpg', 'getFullPath(\'small\') returns the complete small thumbnail path on the disk');
$t->is($sfAsset->getFullPath('large'), sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_sfAssetsLibrary_upload_dir') . DIRECTORY_SEPARATOR . 'thumbnail' . DIRECTORY_SEPARATOR . 'large_filename.jpg', 'getFullPath(\'large\') returns the complete large thumbnail path on the disk');
示例11: dirname
<?php
$app = 'frontend';
include dirname(__FILE__) . '/../bootstrap/functional.php';
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->run(array(), array('sql', 'db', 'and-load', 'no-confirmation', 'application' => $app));
$conn = Doctrine::getConnectionByTableName('Author');
$conn->beginTransaction();
$browser = new sfTestFunctional(new sfBrowser());
$browser->test()->info('Updating first author');
$firstAuthor = Doctrine::getTable('Author')->findOneBySlug('niko');
$browser->get('/author/' . $firstAuthor->slug . '/view')->with('response')->begin()->checkElement('h1', '/niko/')->checkElement('ul#comments li', 1)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->getContext(true)->switchTo('backend');
$firstAuthor->name = 'n1k0';
$firstAuthor->save($conn);
$browser->get('/author/' . $firstAuthor->slug . '/view')->with('response')->begin()->checkElement('h1', '/n1k0/')->checkElement('ul#comments li', 1)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$conn->rollback();
示例12: dirname
<?php
$app = 'frontend';
include dirname(__FILE__) . '/../bootstrap/functional.php';
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->run(array(), array('sql', 'db', 'and-load', 'no-confirmation', 'application' => $app));
$conn = Doctrine::getConnectionByTableName('Article');
$conn->beginTransaction();
$browser = new sfTestFunctional(new sfBrowser());
$browser->get('/en/articles')->with('request')->begin()->isParameter('module', 'content')->isParameter('action', 'index')->isParameter('sf_culture', 'en')->end()->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article/')->checkElement('ul li', '/My second article/', array('position' => 1))->end()->with('view_cache')->begin()->isCached(true, false)->end()->click('My first article')->with('response')->begin()->checkElement('h1', '/My first article/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article with php code - cache invalidation is disabled on frontend');
$firstArticle = Doctrine::getTable('Article')->doSelectForSlug(array('slug' => 'my-first-article'));
$firstArticle->title = 'My first article, cache invalidation is disabled';
$firstArticle->save($conn);
$browser->get('/en/articles')->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article/')->checkElement('ul li:contains("cache invalidation is disabled")', false)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article with php code - switch to backend');
sfContext::switchTo('backend');
$firstArticle = Doctrine::getTable('Article')->doSelectForSlug(array('slug' => 'my-first-article'));
$firstArticle->title = 'My first article, modified';
$firstArticle->save($conn);
sfContext::switchTo('frontend');
$browser->get('/en/articles')->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article, modified/')->checkElement('ul li', '/My second article/', array('position' => 1))->end()->with('view_cache')->begin()->isCached(true, false)->end()->click('My first article, modified')->with('response')->begin()->checkElement('h1', '/My first article, modified/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article from another app (with caching system disabled) - switch to backend');
sfContext::switchTo('backend');
$configuration->loadHelpers('Partial');
$backendBrowser = new sfTestFunctional(new sfBrowser());
$backendBrowser->get('/article/1/edit')->with('request')->begin()->isParameter('module', 'article')->isParameter('action', 'edit')->end()->setField('article[en][title]', 'My first article, edited')->click('Save')->followRedirect()->with('response')->begin()->checkElement('div.notice', 1)->end();
$browser->get('/en/article/' . $firstArticle->slug . '/view')->with('response')->begin()->checkElement('h1', '/My first article, edited/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$conn->rollback();
示例13: _getAuthAdapter
/**
* Function for doing get Authentication of given user's values.
*/
protected function _getAuthAdapter($values)
{
$authAdapter = new ZendX_Doctrine_Auth_Adapter(Doctrine::getConnectionByTableName('Model_Users'));
$encryptedPassword = MD5($values['password']);
$authAdapter->setTableName('Model_Users u')->setIdentityColumn('u.email')->setCredentialColumn('u.password')->setIdentity($values['email'])->setCredential($encryptedPassword);
return $authAdapter;
}
示例14: dirname
<?php
/**
* @author
* @package sfGurardLoginAttempt
* @subpackage unit test
* @version $Id$
*/
include dirname(__FILE__) . '/../bootstrap/bootstrap.php';
$databaseManager = new sfDatabaseManager($configuration);
$conn = Doctrine::getConnectionByTableName('sfGuardLoginAttempt');
$t = new lime_test();
// display some current settings:
$t->info("login_attempts: " . sfConfig::get('app_sf_guard_extra_plugin_login_attempts'));
$t->info("lock_for: " . sfConfig::get('app_sf_guard_extra_plugin_lock_for') . " seconds");
$t->info("lock_timeout: " . sfConfig::get('app_sf_guard_extra_plugin_lock_timeout') . " seconds");
$t->is(false, Doctrine::getTable('sfGuardLoginAttempt')->isLockedOut('127.0.0.1'), "->isLockedOut()");
addFailedLogin();
$t->is(false, Doctrine::getTable('sfGuardLoginAttempt')->isLockedOut('127.0.0.1'), "->isLockedOut() after 1 failed login");
// oh no, someone hammered the web site! ;p
for ($i = 0; $i < 10; $i++) {
addFailedLogin();
}
//$t->comment("Account locked until: ".Doctrine::getTable('sfGuardLoginAttempt')->isLockedOut('127.0.0.1'));
$t->is(true, Doctrine::getTable('sfGuardLoginAttempt')->isLockedOut('127.0.0.1'), "->isLockedOut() after plus 10 failed logins");
/**
* Function used to add a failed login to the database
*/
function addFailedLogin()
{
$tmp = new sfGuardLoginAttempt();
示例15: testGetConnectionByTableName
public function testGetConnectionByTableName()
{
$connectionBefore = Doctrine::getConnectionByTableName('entity');
Doctrine_Manager::connection('sqlite::memory:', 'test_memory');
Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory');
$connectionAfter = Doctrine::getConnectionByTableName('entity');
$this->assertEqual($connectionAfter->getName(), 'test_memory');
Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName());
$connectionAfter = Doctrine::getConnectionByTableName('entity');
$this->assertEqual($connectionBefore->getName(), $connectionAfter->getName());
}