本文整理汇总了PHP中arr::search_collection方法的典型用法代码示例。如果您正苦于以下问题:PHP arr::search_collection方法的具体用法?PHP arr::search_collection怎么用?PHP arr::search_collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::search_collection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: customValidation
public static function customValidation()
{
$base = Event::$data;
if (!$base or !$base instanceof Number) {
return TRUE;
}
$base['number'] = trim($base['number']);
// Get the list of NumberContexts, the generic save will have added
// all contexts in this list but we need to filter invalids (0) and
// unassignments
if (!($assigned_contexts = arr::get($_POST, 'number', 'NumberContext'))) {
$assigned_contexts = array();
}
// Loop each of the number contexts remove those that are not in the
// post'd list or invalid (context_id == 0)
foreach ($base->NumberContext as $pos => $context) {
if (empty($context['context_id']) or !arr::search_collection($assigned_contexts, 'context_id', $context['context_id'])) {
unset($base->NumberContext[$pos]);
}
}
// If there are no contexts left...
if (!$base->NumberContext->count()) {
// see if there are more than one on this account, because if there
// is only one then we know which to assign it to ;)
$contexts = Doctrine::getTable('NumberContext')->findAll();
if ($contexts->count() == 1) {
$base->NumberContext[] = $contexts[0];
} else {
// sorry we tried... what do you want to do?
throw new Exception('Please assign this number to at least one context');
}
}
if (!($assigned_pool = arr::get($_POST, 'number', 'NumberPool'))) {
$assigned_pool = array();
}
foreach ($base->NumberPool as $pos => $pool) {
if (empty($pool['number_type_id']) or !arr::search_collection($assigned_pool, 'number_type_id', $pool['number_type_id'])) {
unset($base->NumberPool[$pos]);
}
}
if (!empty($base['class_type'])) {
$numberType = Doctrine::getTable('NumberType')->findOneByClass($base['class_type']);
if ($number_type_id = arr::get($numberType, 'number_type_id')) {
if (!arr::search_collection($base->NumberPool, 'number_type_id', $number_type_id)) {
$numberPool = new NumberPool();
$numberPool['number_type_id'] = $number_type_id;
$base->NumberPool[] = $numberPool;
}
} else {
kohana::log('error', $base['class_type'] . ' submitted but there is no such pool type!');
throw new Exception('Number does not belong to a number pool matching the destination');
}
}
if (!$base->NumberPool->count()) {
throw new Exception('Please assign this number to at least one number pool');
}
}
示例2: foreach
<ul>
<?php
foreach ($contexts as $context_id => $name) {
?>
<li>
<div class="field">
<?php
echo form::label('context_' . $context_id, $name);
?>
<?php
echo form::checkbox(array('name' => 'number[NumberContext][][context_id]', 'id' => 'context_' . $context_id, 'class' => 'number_context_option'), $context_id, (bool) arr::search_collection($number['NumberContext'], 'context_id', $context_id));
?>
</div>
</li>
<?php
}
?>
</ul>
<?php
echo form::close_section();
?>
示例3: foreach
<ul>
<?php
foreach ($numberTypes['numberTypes'] as $numberType) {
?>
<li>
<div class="field">
<?php
echo form::label('numberType_' . $numberType['number_type_id'], inflector::humanizeModelName(str_replace('Number', '', $numberType['class'])));
?>
<?php
echo form::checkbox(array('name' => 'number[NumberPool][][number_type_id]', 'id' => 'numberType_' . $numberType['number_type_id']), $numberType['number_type_id'], (bool) arr::search_collection($number['NumberPool'], 'number_type_id', $numberType['number_type_id']));
?>
</div>
</li>
<?php
}
?>
</ul>
<?php
echo form::close_section();