本文整理汇总了PHP中EEM_Base::ensure_is_obj方法的典型用法代码示例。如果您正苦于以下问题:PHP EEM_Base::ensure_is_obj方法的具体用法?PHP EEM_Base::ensure_is_obj怎么用?PHP EEM_Base::ensure_is_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EEM_Base
的用法示例。
在下文中一共展示了EEM_Base::ensure_is_obj方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populate_model_obj
/**
* Mostly the same as populate_defaults , except takes a model object as input, not an array,
* and also sets the form's _model_object
* @param EE_Base_Class $model_obj
* @return void
*/
public function populate_model_obj($model_obj)
{
$model_obj = $this->_model->ensure_is_obj($model_obj);
$this->_model_object = $model_obj;
$defaults = $model_obj->model_field_array();
foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) {
$form_inputs = $this->inputs();
if (isset($form_inputs[$relation_name])) {
if ($relation_obj instanceof EE_Belongs_To_Relation) {
//then we only expect there to be one
$related_item = $this->_model_object->get_first_related($relation_name);
$defaults[$relation_name] = $related_item->ID();
} else {
$related_items = $this->_model_object->get_many_related($relation_name);
$ids = array();
foreach ($related_items as $related_item) {
$ids[] = $related_item->ID();
}
$defaults[$relation_name] = $ids;
}
}
}
$this->populate_defaults($defaults);
}
示例2: ensure_is_obj
/**
* Overrides parent ot also check by the slug
* @see EEM_Base::ensure_is_obj()
* @param string|int|EE_Payment_Method $base_class_obj_or_id
* @param boolean $ensure_is_in_db
* @return EE_Payment_Method
* @throws EE_Error
*/
public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE)
{
//first: check if it's a slug
if (is_string($base_class_obj_or_id)) {
$obj = $this->get_one_by_slug($base_class_obj_or_id);
if ($obj) {
return $obj;
}
}
//ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
try {
return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
} catch (EE_Error $e) {
//handle it outside the catch
}
throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id));
}