本文整理汇总了PHP中RedBean_OODBBean::withCondition方法的典型用法代码示例。如果您正苦于以下问题:PHP RedBean_OODBBean::withCondition方法的具体用法?PHP RedBean_OODBBean::withCondition怎么用?PHP RedBean_OODBBean::withCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBean_OODBBean
的用法示例。
在下文中一共展示了RedBean_OODBBean::withCondition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: openList
/**
* Opens a list and returns the contents of the list.
* By default a list is interpreted as the own-list of the current bean.
* If the list begins with the prefix 'shared-' the shared list of the
* bean will be opened instead. Internal method.
*
* @return array
*/
private function openList()
{
$listOfBeans = array();
$listName = strpos($this->list, 'shared-') === 0 ? 'shared' . ucfirst(substr($this->list, 7)) : 'own' . ucfirst($this->list);
if ($this->sqlSnippet) {
if (preg_match('/^(ORDER|GROUP|HAVING|LIMIT|OFFSET|TOP)\\s+/i', ltrim($this->sqlSnippet))) {
$beans = $this->bean->with($this->sqlSnippet, $this->sqlBindings)->{$listName};
} else {
$beans = $this->bean->withCondition($this->sqlSnippet, $this->sqlBindings)->{$listName};
}
} else {
$beans = $this->bean->{$listName};
}
foreach ($beans as $listBean) {
$listOfBeans[] = $listBean->export();
}
return $this->resp($listOfBeans);
}
示例2: findByPath
/**
* Returns the bean identified by the RESTful path.
* For instance:
*
* $user
* /site/1/page/3
*
* returns page with ID 3 in ownPage of site 1 in ownSite of
* $user bean.
*
* Works with shared lists as well:
*
* $user
* /site/1/page/3/shared-ad/4
*
* Note that this method will open all intermediate beans so you can
* attach access control rules to each bean in the path.
*
* @param RedBean_OODBBean $bean
* @param array $steps (an array representation of a REST path)
*
* @return RedBean_OODBBean
*
* @throws RedBean_Exception_Security
*/
public function findByPath($bean, $steps)
{
$numberOfSteps = count($steps);
if (!$numberOfSteps) {
return $bean;
}
if ($numberOfSteps % 2) {
throw new RedBean_Exception_Security('Invalid path: needs 1 more element.');
}
for ($i = 0; $i < $numberOfSteps; $i += 2) {
$steps[$i] = trim($steps[$i]);
if ($steps[$i] === '') {
throw new RedBean_Exception_Security('Cannot access list.');
}
if (strpos($steps[$i], 'shared-') === FALSE) {
$listName = 'own' . ucfirst($steps[$i]);
$listType = $this->toolbox->getWriter()->esc($steps[$i]);
} else {
$listName = 'shared' . ucfirst(substr($steps[$i], 7));
$listType = $this->toolbox->getWriter()->esc(substr($steps[$i], 7));
}
$list = $bean->withCondition(" {$listType}.id = ? ", array($steps[$i + 1]))->{$listName};
if (!isset($list[$steps[$i + 1]])) {
throw new RedBean_Exception_Security('Cannot access bean.');
}
$bean = $list[$steps[$i + 1]];
}
return $bean;
}