本文整理汇总了PHP中Zend_Db_Table::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Table::find方法的具体用法?PHP Zend_Db_Table::find怎么用?PHP Zend_Db_Table::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Table
的用法示例。
在下文中一共展示了Zend_Db_Table::find方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAssociation
/**
* Gets information about association identified by $handle
* Returns true if given association found and not expired and false
* otherwise
*
* @param string $handle association handle
* @param string &$macFunc HMAC function (sha1 or sha256)
* @param string &$secret shared secret
* @param string &$expires expiration UNIX time
* @return bool
*/
public function getAssociation($handle, &$macFunc, &$secret, &$expires)
{
$row = $this->_associationsTable->find($handle)->getRow(0);
if ($row == null) {
return false;
}
if ($row->expires < time()) {
return false;
}
$macFunc = trim($row->mac_func);
// double check $macFunc hasn't got any whitespace
$secret = base64_decode($row->secret);
$expires = $row->expires;
return true;
}
示例2: decComments
/**
* Decrement comments amount
*
* @param integer $count
* @throws Zend_Db_Exception
* @return Comments_Model_CommentAlias
*/
protected function decComments($count = 1)
{
$aliasManager = new Comments_Model_CommentAlias_Manager();
$alias = $aliasManager->getDbTable()->find($this->aliasId)->current();
if ($alias->isKeyRequired() && $alias->isRelatedTableDefined()) {
$table = new Zend_Db_Table($alias->relatedTable);
$row = $table->find($this->key)->current();
if ($row) {
$row->comments -= $count;
$row->save();
} else {
throw new Zend_Db_Exception('Row not found');
}
}
return $this;
}
示例3: viewAction
public function viewAction()
{
$classroom = new Zend_Db_Table('classroom');
$id = Zend_Filter::filterStatic($this->_getParam('id'), 'int');
$rowset = $classroom->find($id);
if (!count($rowset)) {
$this->_redirect('/dashboard');
}
$row = $rowset->current();
$session = new Zend_Session_Namespace('data');
$session->classroom_id = $row->id;
$session->course_id = $row->course_id;
if (in_array('content', Tri_Config::get('tri_plugins', true))) {
$data = Application_Model_Content::fetchAllOrganize($row->course_id);
if (!$data) {
Application_Model_Content::createInitialContent($row->course_id);
$data = Application_Model_Content::fetchAllOrganize($row->course_id);
}
$this->view->current = Application_Model_Content::getLastAccess($id, $data);
$this->view->data = Zend_Json::encode($data);
$session->contents = $this->view->data;
}
$this->_helper->layout->setLayout('layout');
}
示例4: _saveThemeToDb
private function _saveThemeToDb()
{
$templates = glob(INSTALL_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . '*.html');
if (empty($templates)) {
return false;
}
$templateTable = new Zend_Db_Table('template');
foreach ($templates as $template) {
$name = explode(DIRECTORY_SEPARATOR, $template);
$name = str_replace('.html', '', end($name));
$validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'template', 'field' => 'name'));
$tmplRow = $templateTable->find($name);
if ($tmplRow->count()) {
$tmplRow = $tmplRow->current();
$tmplRow->content = file_get_contents($template);
$tmplRow->save();
} else {
$templateTable->insert(array('name' => $name, 'content' => file_get_contents($template), 'type' => 'typeregular'));
}
unset($name);
}
return true;
}
示例5: _refresh
/**
* Refreshes properties from the database.
*/
protected function _refresh()
{
$fresh = $this->_table->find($this->_data[$this->_info['primary']]);
// we can do this because they're both Zend_Db_Table_Row objects
$this->_data = $fresh->_data;
}
示例6: testTableAndIdentityWithVeryLongName
/**
* @group ZF-5674
*/
public function testTableAndIdentityWithVeryLongName()
{
Zend_Db_Table::setDefaultAdapter($this->_db);
// create test table using no identifier quoting
$this->_util->createTable('thisisaveryverylongtablename', array('thisisalongtablenameidentity' => 'IDENTITY', 'stuff' => 'VARCHAR(32)'));
$tableName = $this->_util->getTableName('thisisaveryverylongtablename');
$table = new Zend_Db_Table('thisisaveryverylongtablename');
$row = $table->createRow($this->_getRowForTableAndIdentityWithVeryLongName());
$row->save();
$rowset = $table->find(1);
$this->assertEquals(1, count($rowset));
$this->_util->dropTable('thisisaveryverylongtablename');
}
示例7: addAction
/**
* Add action
*/
public function addAction()
{
// Get the request object
$request = $this->getRequest();
$populateWithDefaultValues = true;
// Check if a form is sent
if ($request->isPost()) {
// Get the post data
$postData = $request->getPost();
$postData = $this->_parsePostData($postData);
if (!isset($postData['form_class']) || isset($postData['form_class']) && $postData['form_class'] == get_class($this->_form)) {
$populateWithDefaultValues = false;
// Populate the post data to the form
$this->_form->populate($postData);
if (isset($this->_form->cancel) && $this->_form->cancel->isChecked()) {
// Cancel button is pressed
$this->_redirect($this->_redirectUrlCancel);
} elseif ($this->validateForm($postData)) {
// Form is sent
try {
// Parse the form data
$item = $this->_getItem('add');
if (array_key_exists('form_class', $item)) {
unset($item['form_class']);
}
if (array_key_exists('form_name', $item)) {
unset($item['form_name']);
}
// Insert the item
$item = $this->_model->insert($item);
if (!is_array($item)) {
$item = array($item);
}
switch (count($item)) {
case 0:
break;
case 1:
$this->_item = $this->_model->find($item[0])->current();
break;
case 2:
$this->_item = $this->_model->find($item[0], $item[1])->current();
break;
case 3:
$this->_item = $this->_model->find($item[0], $item[1], $item[2])->current();
break;
case 4:
$this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3])->current();
break;
case 5:
$this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4])->current();
break;
case 6:
$this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4], $item[5])->current();
break;
case 7:
$this->_item = $this->_model->find($item[0], $item[1], $item[2], $item[3], $item[4], $item[5], $item[6])->current();
break;
}
// Actions after the query
$this->_afterQuery('add');
$this->_flashMessenger->addMessage('Added the item succesfully.');
// Redirect
$this->_redirect($this->_redirectUrlAdd);
} catch (Exception $exception) {
$this->_form->addErrorMessage($exception->getMessage());
}
}
}
}
if ($populateWithDefaultValues) {
// Initialize the form with default values
$this->_form->populate($this->_getDefaultFormValues());
}
// Set the class "error" to subforms with errors
// Set the class "error" to subforms with errors
if (method_exists($this->_form, 'setErrorClass')) {
$this->_form->setErrorClass('error');
}
// Parse the form to the view
$this->view->form = $this->_form;
}
示例8: accountAction
public function accountAction()
{
// Leave if not ready
if (empty($this->_session->mysql)) {
return $this->_helper->redirector->gotoRoute(array('action' => 'db-info'));
}
$this->view->form = $form = new Install_Form_Account();
if (!$this->getRequest()->isPost()) {
return;
}
if (!$form->isValid($this->getRequest()->getPost())) {
return;
}
// Check passwords match
$values = $form->getValues();
if ($values['password'] != $values['password_conf']) {
$form->addError('Passwords must match.');
return;
}
// Create account
// Connect again
try {
$config = $this->dbFormToConfig($this->_session->mysql);
// Connect!
$adapter = Zend_Db::factory($config['adapter'], $config['params']);
$adapter->getServerVersion();
} catch (Exception $e) {
$form->addError('Adapter Error: ' . $e->getMessage());
//$this->view->code = 1;
//$this->view->error = 'Adapter Error: ' . $e->getMessage();
return;
}
// attempt to disable strict mode
try {
$adapter->query("SET SQL_MODE = ''");
} catch (Exception $e) {
}
try {
// Preprocess
$settingsTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_core_settings'));
$usersTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_users'));
$levelTable = new Zend_Db_Table(array('db' => $adapter, 'name' => 'engine4_authorization_levels'));
// Get static salt
$staticSalt = $settingsTable->find('core.secret')->current();
if (is_object($staticSalt)) {
$staticSalt = $staticSalt->value;
} else {
if (!is_string($staticSalt)) {
$staticSalt = '';
}
}
// Get superadmin level
$superAdminLevel = $levelTable->fetchRow($levelTable->select()->where('flag = ?', 'superadmin'));
if (is_object($superAdminLevel)) {
$superAdminLevel = $superAdminLevel->level_id;
} else {
$superAdminLevel = 1;
}
// Temporarily save pw
$originalPassword = $values['password'];
// Adjust values
$values['salt'] = (string) rand(1000000, 9999999);
$values['password'] = md5($staticSalt . $values['password'] . $values['salt']);
$values['level_id'] = $superAdminLevel;
$values['enabled'] = 1;
$values['verified'] = 1;
$values['creation_date'] = date('Y-m-d H:i:s');
$values['creation_ip'] = ip2long($_SERVER['REMOTE_ADDR']);
$values['displayname'] = $values['username'];
// Try to write info to config/auth.php
if (!$this->_writeAuthToFile($values['email'], 'seiran', $originalPassword)) {
throw new Exception('Unable to write Auth to File');
}
// Insert
$row = $usersTable->createRow();
$row->setFromArray($values);
$row->save();
// First Signup Increment
// Engine_Api::_()->getDbtable('statistics', 'core')->increment('user.creations');
// Validate password
if ($row->password != md5($staticSalt . $originalPassword . $row->salt)) {
throw new Engine_Exception('Error creating password');
}
// Log the user into the intaller
$auth = Zend_Registry::get('Zend_Auth');
$auth->getStorage()->write($row->user_id);
// Try to log the user into socialengine
// Note: nasty hack
try {
$mainSessionName = 'PHPSESSID';
if (empty($_COOKIE[$mainSessionName])) {
$mainSessionId = md5(mt_rand(0, time()) . serialize($_SERVER));
setcookie($mainSessionName, $mainSessionId, null, dirname($this->view->baseUrl()), $_SERVER['HTTP_HOST'], false, false);
} else {
$mainSessionId = $_COOKIE[$mainSessionName];
}
$adapter->insert('engine4_core_session', array('id' => $mainSessionId, 'modified' => time(), 'lifetime' => 86400, 'data' => 'Zend_Auth|' . serialize(array('storage' => $row->user_id))));
} catch (Exception $e) {
// Silence
if (APPLICATION_ENV == 'development') {
//.........这里部分代码省略.........
示例9: testTableRelationshipCanFindManyToManyRowsetViaConcreteInstantiation
/**
* @group ZF-3486
*/
public function testTableRelationshipCanFindManyToManyRowsetViaConcreteInstantiation()
{
Zend_Db_Table::setDefaultAdapter($this->_db);
$definition = $this->_getTableDefinition();
$bugsTable = new Zend_Db_Table('Bugs', $definition);
$bugsRowset = $bugsTable->find(1);
$bugRow = $bugsRowset->current();
$m2mRowset = $bugRow->findManyToManyRowset('Products', 'BugsProducts');
$this->assertEquals(3, $m2mRowset->count());
}
示例10: _authDb
protected function _authDb($identity, $credential)
{
$auth = Zend_Registry::get('Zend_Auth');
// Check if it's possible to authenticate
if (!Zend_Registry::isRegistered('Zend_Db') || !($db = Zend_Registry::get('Zend_Db')) instanceof Zend_Db_Adapter_Abstract) {
throw new Engine_Exception('Unable to authenticate, no database connection present');
}
// Make user table and level table
try {
$userTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_users'));
$userTable->info();
// Forces check on table existence
$levelTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_authorization_levels'));
$levelTable->info();
// Forces check on table existence
$settingsTable = new Zend_Db_Table(array('db' => $db, 'name' => 'engine4_core_settings'));
$settingsTable->info();
// Forces check on table existence
} catch (Exception $e) {
throw new Engine_Exception('Unable to authenticate, missing database tables');
}
// Try to authenticate
try {
// Get static salt
$staticSalt = $settingsTable->find('core.secret')->current();
if (is_object($staticSalt)) {
$staticSalt = $staticSalt->value;
} else {
$staticSalt = '';
}
// Get superadmin levels
$saLevels = $levelTable->select()->where('flag = ?', 'superadmin')->query()->fetchAll();
$saLevelIds = array();
foreach ((array) $saLevels as $dat) {
if (is_numeric($dat['level_id'])) {
$saLevelIds[] = $dat['level_id'];
}
}
if (empty($saLevelIds)) {
return $form->addError('No admin levels');
}
$saLevelStr = "'" . join("','", $saLevelIds) . "'";
// Authenticate
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'engine4_users', 'email', 'password', "MD5(CONCAT('" . $staticSalt . "', ?, salt)) && `level_id` IN({$saLevelStr})");
$authAdapter->setIdentity($identity)->setCredential($credential);
$authResult = $auth->authenticate($authAdapter);
} catch (Exception $e) {
throw new Engine_Exception('An error occurred');
}
// Check result
$authCode = $authResult->getCode();
if ($authCode != Zend_Auth_Result::SUCCESS) {
return false;
}
return true;
}
示例11: find
public function find()
{
return parent::find();
}