本文整理汇总了PHP中Zend::registry方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend::registry方法的具体用法?PHP Zend::registry怎么用?PHP Zend::registry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend
的用法示例。
在下文中一共展示了Zend::registry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: regformAction
public function regformAction()
{
// show reg form
$view = Zend::registry("view");
$view->title = "User Registration";
print $view->render('user/regform.php');
}
示例2: __construct
function __construct($config = array())
{
// set a Zend_Db_Adapter connection
if (!empty($config['db'])) {
// convenience variable
$db = $config['db'];
// use an object from the registry?
if (is_string($db)) {
$db = Zend::registry($db);
}
// make sure it's a Zend_Db_Adapter
if (!$db instanceof Zend_Db_Adapter_Abstract) {
throw new Varien_Db_Tree_Exception('db object does not implement Zend_Db_Adapter_Abstract');
}
// save the connection
$this->_db = $db;
$conn = $this->_db->getConnection();
if ($conn instanceof PDO) {
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
} elseif ($conn instanceof mysqli) {
//TODO: ???
}
} else {
throw new Varien_Db_Tree_Exception('db object is not set in config');
}
if (!empty($config['table'])) {
$this->setTable($config['table']);
}
if (!empty($config['id'])) {
$this->setIdField($config['id']);
} else {
$this->setIdField('id');
}
if (!empty($config['left'])) {
$this->setLeftField($config['left']);
} else {
$this->setLeftField('left_key');
}
if (!empty($config['right'])) {
$this->setRightField($config['right']);
} else {
$this->setRightField('right_key');
}
if (!empty($config['level'])) {
$this->setLevelField($config['level']);
} else {
$this->setLevelField('level');
}
if (!empty($config['pid'])) {
$this->setPidField($config['pid']);
} else {
$this->setPidField('parent_id');
}
}
示例3: routeShutdown
public function routeShutdown($action)
{
$user = Zend::registry('user');
if ($user->getPermission($action->getControllerName(), $action->getActionName())) {
return $action;
} else {
$action->setControllerName('index');
$action->setActionName('unauthorized');
return $action;
}
}
示例4: __construct
/**
* @param array $config
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function __construct($config = [])
{
// set a \Zend_Db_Adapter connection
if (!empty($config['db'])) {
// convenience variable
$connection = $config['db'];
// use an object from the registry?
if (is_string($connection)) {
$connection = \Zend::registry($connection);
}
// make sure it's a \Zend_Db_Adapter
if (!$connection instanceof \Zend_Db_Adapter_Abstract) {
throw new LocalizedException(new \Magento\Framework\Phrase('db object does not implement \\Zend_Db_Adapter_Abstract'));
}
// save the connection
$this->_db = $connection;
$conn = $this->_db->getConnection();
if ($conn instanceof \PDO) {
$conn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
}
} else {
throw new LocalizedException(new \Magento\Framework\Phrase('db object is not set in config'));
}
if (!empty($config['table'])) {
$this->setTable($config['table']);
}
if (!empty($config['id'])) {
$this->setIdField($config['id']);
} else {
$this->setIdField('id');
}
if (!empty($config['left'])) {
$this->setLeftField($config['left']);
} else {
$this->setLeftField('left_key');
}
if (!empty($config['right'])) {
$this->setRightField($config['right']);
} else {
$this->setRightField('right_key');
}
if (!empty($config['level'])) {
$this->setLevelField($config['level']);
} else {
$this->setLevelField('level');
}
if (!empty($config['pid'])) {
$this->setPidField($config['pid']);
} else {
$this->setPidField('parent_id');
}
}
示例5: nowaAction
/**
* Tworzy now� ankiet� i przekierowuje do akcji edytujAction
*/
public function nowaAction()
{
$post = new Zend_Filter_Input($_POST);
$user = Zend::registry('user');
$poll = new Ankiety();
$data = array('nazwa' => $post->getRaw('ankieta_nazwa'), 'opis' => $post->getRaw('ankieta_opis'), 'id_uzytkownik' => 1);
try {
$id = $poll->insert($data);
$this->_forward('ankieter', 'edytuj', array('ankieta' => $id));
} catch (Hamster_Validation_Exception $e) {
$this->_forward('ankieter', 'index', array('validationError' => $e->getMessage()));
}
}
示例6: __construct
/**
* Constructor.
*
* @param array $config Array of user-specified config options.
*/
public function __construct($config = null)
{
// set a custom Zend_Db_Adapter connection
if (!empty($config['db'])) {
// convenience variable
$db = $config['db'];
// use an object from the registry?
if (is_string($db)) {
$db = Zend::registry($db);
}
// make sure it's a Zend_Db_Adapter
if (!$db instanceof Zend_Db_Adapter_Abstract) {
throw new Zend_Db_Table_Exception('db object does not implement Zend_Db_Adapter_Abstract');
}
// save the connection
$this->_db = $db;
}
// set the inflector
self::$_inflector = new Zend_Db_Inflector();
// continue with automated setup
$this->_setup();
}
示例7: testRegistry
/**
* Tests that:
* 1. an object can be registered with register().
* 2. attempting to register the same object throws an exception.
* 3. the object is returned by registry('objectName').
* 4. the object is listed in the array returned by registry().
*/
public function testRegistry()
{
/**
* Register an object
*/
$obj = new stdClass();
// throws exception on failure
Zend::register('objectName', $obj);
/**
* Attempt to register the same object again
*/
$e = null;
try {
Zend::register('another', $obj);
} catch (Zend_Exception $e) {
$this->assertRegExp('/duplicate(.*)objectName/i', $e->getMessage());
}
if ($e === null) {
$this->fail('No exception thown during registration of duplicate object.');
}
/**
* Attempt to retrieve the object with registry()
*/
$this->assertSame(Zend::registry('objectName'), $obj);
/**
* Check registry listing
*/
$this->assertEquals(Zend::registry(), array('objectName' => 'stdClass'));
}
示例8: logoutAction
public function logoutAction()
{
$user = Zend::registry('user');
$user->logout();
$this->_redirect('/index/index');
}
示例9: __construct
public function __construct()
{
$this->db = Zend::registry('db');
}
示例10:
<div id="bluebox">
<div id="bluebox_body">
<?php
$user = Zend::registry('user');
if ($user->getUserId() == 0) {
?>
<form action="/index/login" method="post">
<label for="input_login">LOGIN</label>
<div>
<input type="text" class="input_classic" id="input_login" name="input_login">
</div>
<label for="input_haslo">HASŁO</label>
<div>
<input type="text" class="input_classic" id="input_haslo" name="input_haslo">
</div>
<input type="submit" value="zaloguj się" id="input_submit">
</form>
<?php
} else {
echo 'Zalogowany jako <b>' . $user->getLogin() . '</b> ';
echo '<a href="/index/logout">wygoluj się</a>';
}
?>
</div>
<div id="bluebox_bottom"></div>
</div>
示例11: deleteRecord
/**
* Delete this record and delete its duration from the task
* TODO: Remove once this is ported!
*/
public function deleteRecord()
{
$user = za()->getUser();
$db = Zend::registry('DbService');
$taskId = $this->taskid;
$select = $db->select();
$select->from('task', '*')->where('id = ?', $taskId);
$task = $db->getObject($select, 'task');
if ($task == null) {
throw new Exception("Task ID " . $taskId . " does not exist");
}
$toDelete = $this->endtime - $this->starttime;
try {
$db->delete($this, 'id=' . $this->id);
// Get the total time for this task. $select = $db->select();
$select = $db->select();
$select->from('timesheetrecord', new Zend_Db_Expr('SUM(endtime - starttime) AS tasktime'))->where('taskid = ?', $taskId);
$row = $db->fetchAll($select);
$total = $row[0]['tasktime'];
if ($total > 0) {
// hours = timespent / 3600
$task->timespent = $task->timespent - $toDelete;
$task->save();
}
} catch (Exception $e) {
$this->log->err($e->getTraceAsString());
throw $e;
}
}
示例12: testRegistry
/**
* Tests that:
* 1. an object can be registered with register().
* 2. the object is returned by registry('objectName').
* 3. the object is listed in the ArrayObject returned by registry().
* 4. isRegistered() returns correct states.
*/
public function testRegistry()
{
$registry = Zend::registry();
$this->assertFalse($registry->offsetExists('objectName'));
$subregistry = new Zend_Registry(array('option1' => 'setting1', 'option2' => 'setting2'));
// throws exception on failure
Zend::register('componentOptions', $subregistry);
$this->assertTrue($registry->offsetExists('componentOptions'));
// compare fetched value with the expected value
$this->assertSame(Zend::registry('componentOptions'), $subregistry);
$this->assertTrue($registry->offsetGet('componentOptions') == new Zend_Registry(array('option1' => 'setting1', 'option2' => 'setting2')));
// Make sure a second object can be registered
$object2 = new stdClass();
$this->assertNotSame($subregistry, $object2);
// throws exception on failure
$registry->offsetSet('componentOptions', $object2);
$this->assertTrue($registry->offsetExists('componentOptions'));
$this->assertNotSame(Zend::registry('componentOptions'), $subregistry);
$this->assertSame(Zend::registry('componentOptions'), $object2);
}