本文整理汇总了PHP中Model::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getId方法的具体用法?PHP Model::getId怎么用?PHP Model::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetId
public function testSetId()
{
$this->ormMock->expects($this->once())->method('setValue')->with('id', 2);
$this->ormMock->expects($this->any())->method('getValue')->with('id')->will($this->returnValue(2));
$this->model->id = 2;
$this->assertEquals(2, $this->model->getId());
}
示例2: isSameAs
/**
* Find if two objects represent the same model
*
* @param Model $model The model to compare
* @return bool
*/
public function isSameAs(Model $model)
{
if (!$this->isValid() || !$model->isValid()) {
return false;
}
$sameType = $this instanceof $model || $model instanceof $this;
return $sameType && $this->getId() === $model->getId();
}
示例3: testDocumentCommentWithPostData
/**
* Test
*
* @return void
*/
public function testDocumentCommentWithPostData()
{
$this->dispatch('/admin/module/blog/document-comment/' . $this->document->getId(), 'POST', array('comment' => array('1' => array('delete' => true), '2' => array('message' => true, 'wrong-name' => false))));
$this->assertResponseStatusCode(302);
$this->assertModuleName('Blog');
$this->assertControllerName('BlogController');
$this->assertControllerClass('IndexController');
$this->assertMatchedRouteName('module/blog/document-comment');
}
示例4: getModelName
/**
* Get the name of any model
*
* @param \Model $model
* @return string The name of the model
*/
private function getModelName($model)
{
if ($model instanceof \NamedModel) {
return $model->getName();
}
if ($model instanceof \AliasModel) {
return $model->getAlias();
}
return $model->getId();
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (isset($options['include'])) {
$this->include = $options['include'];
}
if (isset($options['multiple'])) {
$this->multiple = $options['multiple'];
}
if ($this->include && !$this->multiple) {
throw new \LogicException("You can't include an object in a single selection!");
}
$builderName = ucfirst($builder->getName());
// TODO: Use a more accurate placeholder
$placeholder = $this->multiple ? 'brad, kierra, ...' : null;
if ($this->include) {
$exclude = $this->include->getType() . ':' . $this->include->getId();
} else {
$exclude = null;
}
// Model IDs that will be manipulated by javascript
$builder->add('ids', 'hidden', array('attr' => array('class' => 'select2-compatible', 'data-exclude' => $exclude, 'data-label' => $builderName, 'data-multiple' => $this->multiple, 'data-required' => $options['required'])));
// Model name inputs that will be edited by users if javascript is
// disabled
foreach ($this->types as $type) {
$pluralType = $this->multiple ? Inflector::pluralize($type) : $type;
$label = count($this->types) > 1 ? "{$builderName} {$pluralType}" : $builderName;
$builder->add($builder->create($type, 'text', array('attr' => array('class' => 'model-select', 'data-type' => $type, 'placeholder' => $placeholder), 'label' => $label, 'required' => false)));
}
if ($this->multiple) {
$transformer = new MultipleAdvancedModelTransformer($this->types);
if ($this->include) {
$transformer->addInclude($this->include);
}
} else {
$transformer = new SingleAdvancedModelTransformer($this->types);
}
$builder->addViewTransformer($transformer);
// Make sure we can change the values provided by the user
$builder->setDataLocked(false);
}
示例6: getAllModels
/**
* This returns all models sorted by Make Title, then Model Title
*
* @return \SquirrelsInventory\Model[]
*/
public static function getAllModels()
{
$models = array();
$makes = Make::getAllMakes();
$parents = array(0 => array());
foreach ($makes as $make_id => $make) {
$parents[$make_id] = array();
}
$query = new \WP_Query(array('post_type' => self::CUSTOM_POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$custom = get_post_custom(get_the_ID());
$model = new Model(get_the_ID(), get_the_title());
if (array_key_exists('make_id', $custom)) {
$make_id = $custom['make_id'][0];
$model->setMakeId($make_id);
if (array_key_exists($model->getMakeId(), $makes)) {
$model->setMake($makes[$model->getMakeId()]);
}
} else {
$make_id = 0;
}
$parents[$make_id][] = $model;
}
}
foreach ($parents as $parent_id => $_models) {
/** @var Model[] $_models */
foreach ($_models as $model) {
$models[$model->getId()] = $model;
}
}
return $models;
}
示例7: Model
}
/**
* Edit a model
*/
if ($action == 'edit') {
// Get ID
$id = fRequest::get('id', 'integer');
try {
// Get model via ID
$m = new Model($id);
if (fRequest::isPost()) {
// Update model object from POST data and save
$m->populate();
$m->store();
// Messaging
fMessaging::create('affected', fURL::get(), $m->getId());
fMessaging::create('success', fURL::get(), 'The model ' . $m->getName() . ' was successfully updated.');
fURL::redirect(fURL::get());
}
} catch (fNotFoundException $e) {
fMessaging::create('error', fURL::get(), 'The model requested, ID ' . $id . ', could not be found.');
fURL::redirect(fURL::get());
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
// Get manufacturers also for drop-down box
$manufacturers = fRecordSet::build('Manufacturer', NULL, array('name' => 'asc'));
include 'views/models/addedit.php';
}
/**
* Delete a model
示例8: scaffold
public function scaffold(Model $model, $action = "", $variants = array(), $attrs = null)
{
$attrs = $this->parseHtmlAttrs($attrs);
$result = "<form method=\"post\" action=\"{$action}\"{$attrs}><ol>";
$fields = $model->getAttributes(true);
$result .= $this->hidden("id", $model->getId());
foreach ($fields as $name => $type) {
if ($variants[$name] === false) {
$result .= $this->hidden($name, $model->{$name});
continue;
}
$label = ucfirst(strtolower(str_replace("_", " ", preg_replace("/([A-Z])/", " \$1", $name))));
switch ($type) {
case Model::TYPE_INTEGER:
case Model::TYPE_SET:
case Model::TYPE_ENUM:
if (is_array($variants[$name]) || $variants[$name] instanceof Iterator || $variants[$name] instanceof IteratorAggregate) {
$result .= "<li>" . $this->select($name, $variants[$name], $model->{$name}, $label) . "</li>";
} else {
$result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name]) . "</li>";
}
break;
case Model::TYPE_FLOAT:
$result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name]) . "</li>";
break;
case Model::TYPE_STRING:
$result .= "<li>" . $this->input($name, $model->{$name}, $label, $variants[$name], 80) . "</li>";
break;
case Model::TYPE_BOOLEAN:
$result .= "<li>" . $this->checkbox($name, $model->{$name}, $label) . "</li>";
break;
case Model::TYPE_TIMESTAMP:
$date = localtime($model->{$name});
$result .= "<li>" . $this->selectDate($name, $model->{$name}, $label, "dmyhs") . "</li>";
break;
}
}
$result .= "<li class=\"reset\"><input type=\"reset\" value=\"Reset\" /></li>";
$result .= "<li class=\"submit\"><input type=\"submit\" value=\"Save\" /></li>";
$result .= "</ol></form>";
return $result;
}
示例9: setModel
/**
* @param Model $model
*
* @return Auto
*/
public function setModel($model)
{
$this->model = $model;
$this->model_id = $model->getId();
return $this;
}
示例10: update
/**
* The "U" in CRUD
* This could be collapsed under create, for now it's separate for better debugging
* It's important to note that edit requires a FileMaker -recid that should be
* passed as a hidden form field
*
* @param Model $model
* @param array $fields
* @param array $values
* @param mixed $conditions
* @return array
*/
function update(&$model, $fields = array(), $values = null, $conditions = null)
{
// get connection parameters
$fm_database = empty($model->fmDatabaseName) ? $this->config['database'] : $model->fmDatabaseName;
$fm_layout = empty($model->defaultLayout) ? $this->config['defaultLayout'] : $model->defaultLayout;
if (!empty($model->id)) {
// set basic connection data
$this->connection->SetDBData($fm_database, $fm_layout);
// **1 here we remove the primary key field if it's marked as readonly
// other fields can be removed by the controller, but cake requires
// the primary key to be included in the query if it's to consider
// the action an edit
foreach ($fields as $index => $field) {
if (isset($model->primaryKeyReadOnly) && $field == $model->primaryKey) {
unset($fields[$index]);
unset($values[$index]);
}
}
// ensure that a recid is passed
if (!in_array('-recid', $fields)) {
array_push($fields, '-recid');
array_push($values, $model->getId());
}
// there must be a -recid field passed in here for the edit to work
// could be passed in hidden form field
foreach ($fields as $index => $field) {
$this->connection->AddDBParam($field, $values[$index]);
}
// perform edit
$return = $this->connection->FMEdit();
if (!$this->handleFXResult($return, $model->name, 'update')) {
return FALSE;
}
if ($return['errorCode'] != 0) {
return false;
} else {
foreach ($return['data'] as $recmodid => $returnedModel) {
$recmodid_Ary = explode('.', $recmodid);
$model->id = $recmodid_Ary[0];
$model->setInsertID($recmodid_Ary[0]);
}
return true;
}
} else {
return false;
}
}
示例11: startAt
/**
* Start with a specific result
*
* @param int|Model $model The model (or database ID) before the first result
* @param bool $inclusive Whether to include the provided model
* @param bool $reverse Whether to reverse the results
* @return self
*/
public function startAt($model, $inclusive = false, $reverse = false)
{
if (!$model) {
return $this;
} elseif ($model instanceof Model && !$model->isValid()) {
return $this;
}
$this->column($this->sortBy);
$this->limited = true;
$column = $this->currentColumn;
$table = $this->getTable();
$comparison = $this->reverseSort ^ $reverse;
$comparison = $comparison ? '>' : '<';
$comparison .= $inclusive ? '=' : '';
$id = $model instanceof Model ? $model->getId() : $model;
// Compare an element's timestamp to the timestamp of $model; if it's the
// same, perform the comparison using IDs
$this->addColumnCondition("{$comparison} (SELECT {$column} FROM {$table} WHERE id = ?) OR ({$column} = (SELECT {$column} FROM {$table} WHERE id = ?) AND id {$comparison} ?)", array($id, $id, $id), 'iii');
return $this;
}
示例12: add
/**
* Setters
*/
public function add(Model $model)
{
$this->models[$model->getId()] = $model;
}
示例13: setModel
/**
* Declares an association between this object and a Model object.
*
* @param Model $v
* @return Score The current object (for fluent API support)
* @throws PropelException
*/
public function setModel(Model $v = null)
{
if ($v === null) {
$this->setModelId(NULL);
} else {
$this->setModelId($v->getId());
}
$this->aModel = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the Model object, it will not be re-added.
if ($v !== null) {
$v->addScore($this);
}
return $this;
}
示例14: editInventory
public function editInventory()
{
if (strlen($_REQUEST['new_make']) > 0 && strlen($_REQUEST['new_model']) > 0) {
$make = new Make();
$make->setTitle($_REQUEST['new_make'])->create();
$model = new Model();
$model->setTitle($_REQUEST['new_model'])->setMake($make)->create();
} else {
$model = new Model($_REQUEST['model_id']);
$model->loadMake();
}
$auto = new Auto($_REQUEST['id']);
$auto->setPrice($_REQUEST['price'])->setPricePostfix($_REQUEST['price_postfix'])->setTypeId($_REQUEST['type_id'])->setInventoryNumber($_REQUEST['inventory_number'])->setVin($_REQUEST['vin'])->setMakeId($model->getMakeId())->setModelId($model->getId())->setYear($_REQUEST['year'])->setDescription($_REQUEST['description'])->setIsVisible($_REQUEST['is_visible'])->setIsFeatured($_REQUEST['is_featured'])->setInterior($_REQUEST['interior'])->setExterior($_REQUEST['exterior'])->setOdometerReading($_REQUEST['odometer_reading']);
/* Features */
$auto->setFeatures(NULL);
$features = json_decode(stripslashes($_REQUEST['features']), TRUE);
foreach ($features as $f) {
if ($f['remove'] == 0) {
$feature = new AutoFeature();
$feature->setId(uniqid())->setFeatureId($f['feature_id'])->setFeatureTitle($f['title'])->setValue($f['value'])->setCreatedAt(time())->setUpdatedAt(time());
$auto->addFeature($feature);
}
}
$auto->update();
$images = json_decode(stripslashes($_REQUEST['images']), TRUE);
/** Remove deleted images */
if ($auto->getImageCount() > 0) {
foreach ($auto->getImages() as $image) {
$delete_me = TRUE;
foreach ($images as $i) {
if ($image->getId() == $i['id']) {
$delete_me = FALSE;
break;
}
}
if ($delete_me) {
$auto->deleteImage($image->getId());
}
}
}
foreach ($images as $i) {
/** Add new images */
if ($i['id'] == 0) {
$image = new Image();
$image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->create();
$auto->addImage($image);
} else {
$image = new Image($i['id']);
$image->setInventoryId($auto->getId())->setMediaId($i['media_id'])->setUrl($i['url'])->setIsDefault($i['def'])->update();
$auto->setImage($i['id'], $image);
}
}
return $auto->getId();
}
示例15: addInstanceToPool
/**
* Adds an object to the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doSelect*()
* methods in your stub classes -- you may need to explicitly add objects
* to the cache in order to ensure that the same objects are always returned by doSelect*()
* and retrieveByPK*() calls.
*
* @param Model $value A Model object.
* @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
*/
public static function addInstanceToPool(Model $obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if ($key === null) {
$key = (string) $obj->getId();
}
// if key === null
self::$instances[$key] = $obj;
}
}