本文整理汇总了PHP中Track::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Track::model方法的具体用法?PHP Track::model怎么用?PHP Track::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Track
的用法示例。
在下文中一共展示了Track::model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restEvents
public function restEvents()
{
/**
* req.get.resources.render
*
* Called when a GET request for when a list resources is to be rendered
*
* @param (Array) (data) this is an array of models representing the resources
* @param (String) (model_name) the name of the resources model
* @param (Array) (relations) the list of relations to include with the data
* @param (Int) (count) the count of records to return
*/
$this->onRest('req.get.resources.render', function ($data, $model_name, $relations, $count) {
//Handler for GET (list resources) request
$this->setHttpStatus($count > 0 ? 200 : 204);
$this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record(s) Found" : "No Record(s) Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
});
/**
* req.get.resource.render
*
* Called when a GET request for a single resource is to be rendered
* @param (Object) (data) this is the resources model
* @param (String) (model_name) the name of the resources model
* @param (Array) (relations) the list of relations to include with the data
* @param (Int) (count) the count of records to return (will be either 1 or 0)
*/
$this->onRest('req.get.resource.render', function ($data, $model_name, $relations, $count) {
//Handler for GET (single resource) request
$this->setHttpStatus($count > 0 ? 200 : 204);
$this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record Found" : "No Record Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
});
$this->onRest('req.post.album.', function ($data) {
//$data is the data sent in the POST
echo CJSON::encode(array('data' => $data));
});
/**
* model.delete
*
* Called whenever a model resource needs deleting
*
* @param (Object) (model) the model resource to be deleted
*/
$this->onRest('model.delete', function ($artist) {
/*print_r(Artist::PROTECTED_ARTISTS());
print_r($artist->id);
exit;*/
//DON'T LET USERS DELETE PROTECTED ARTISTS
if (in_array($artist->id, Artist::PROTECTED_ARTISTS())) {
throw new CHttpException(403, '<i>You cannot delete </i><h4>' . $artist->name . '</h4><br> It\'s demo data.Feel free to create,update and delete your own data.');
exit;
}
$albumsDeleted = true;
$tracksDeleted = true;
foreach ($artist->albums as $album) {
//delete tracks
$albumid = $album->id;
$tracks = Track::model()->findAllByAttributes(array('album_id' => $albumid));
foreach ($tracks as $track) {
$trackDeleted = $track->delete();
$tracksDeleted = $tracksDeleted && $trackDeleted;
}
//delete album
$albumdeleted = $album->delete();
$albumsDeleted = $albumsDeleted && $albumdeleted;
}
if (!$artist->delete()) {
throw new CHttpException(500, 'Could not delete model');
}
if (!$albumsDeleted) {
throw new CHttpException(500, 'Some artist\'s albums were not deleted');
}
if (!$tracksDeleted) {
throw new CHttpException(500, 'Some album tracks were not deleted');
}
if (!$this->unlinkArtistFromAlbums($artist->id)) {
throw new CHttpException(500, 'Artist was not unlinked from albums.');
}
return $artist;
});
//DON'T LET USERS UPDATE PROTECTED ARTISTS
$this->onRest('pre.filter.model.apply.put.data', function ($model, $data, $restricted_properties) {
if (in_array($model->id, Artist::PROTECTED_ARTISTS())) {
throw new CHttpException(403, '<i>You cannot modify </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete your own data.');
exit;
} else {
return array($model, $data, $restricted_properties);
}
//Array [Object, Array, Array]
});
/**
* model.subresources.save
*
* Called whenever a sub-resource is saved
*
* @param (Object) (model) the owner of the sub-resource
* @param (String) (subresource_name) the name of the subresource
* @param (Mixed/Int) (subresource_id) the primary key of the subresource
*
* @return (Object) the updated model representing the owner of the sub-resource
*/
//.........这里部分代码省略.........
示例2: restEvents
public function restEvents()
{
/**
* req.get.resources.render
*
* Called when a GET request for when a list resources is to be rendered
*
* @param (Array) (data) this is an array of models representing the resources
* @param (String) (model_name) the name of the resources model
* @param (Array) (relations) the list of relations to include with the data
* @param (Int) (count) the count of records to return
*/
$this->onRest('req.get.resources.render', function ($data, $model_name, $relations, $count) {
//Handler for GET (list resources) request
$this->setHttpStatus($count > 0 ? 200 : 204);
$this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record(s) Found" : "No Record(s) Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
});
/**
* req.get.resource.render
*
* Called when a GET request for a single resource is to be rendered
* @param (Object) (data) this is the resources model
* @param (String) (model_name) the name of the resources model
* @param (Array) (relations) the list of relations to include with the data
* @param (Int) (count) the count of records to return (will be either 1 or 0)
*/
$this->onRest('req.get.resource.render', function ($data, $model_name, $relations, $count) {
//Handler for GET (single resource) request
$this->setHttpStatus($count > 0 ? 200 : 204);
$this->renderJSON(array('type' => 'rest', 'success' => $count > 0 ? true : false, 'message' => $count > 0 ? "Record Found" : "No Record Found", 'totalCount' => $count, 'modelName' => $model_name, 'relations' => $relations, 'data' => $data));
});
$this->onRest('pre.filter.model.apply.put.data', function ($model, $data, $restricted_properties) {
$artist_id = $model->artists[0]->id;
if (in_array($artist_id, Artist::PROTECTED_ARTISTS())) {
throw new CHttpException(403, '<i>You cannot modify </i><h4>' . $model->name . '</h4><br> It\'s demo data.Feel free to create,update and delete your own data.');
exit;
} else {
return [$model, $data, $restricted_properties];
}
//Array [Object, Array, Array]
});
/**
* model.delete
*
* Called whenever a model resource needs deleting
*
* @param (Object) (model) the model resource to be deleted
*/
/* $this->onRest('model.delete', function ($model) {
$artist_id = $model->artists[0]->id;
if (in_array($artist_id, Artist::PROTECTED_ARTISTS())) {
throw new CHttpException(403, '<i>You cannot delete </i><h4>' . $model->name .
'</h4><br> It\'s demo data.Feel free to create,update and delete your own data.');
exit;
} else {
if (!$model->delete()) {
throw new CHttpException(500, 'Could not delete model');
}
}
return $model;
});*/
$this->onRest('model.delete', function ($album) {
$artist_id = $album->artists[0]->id;
if (in_array($artist_id, Artist::PROTECTED_ARTISTS())) {
throw new CHttpException(403, '<i>You cannot delete </i><h4>' . $album->name . '</h4><br> It\'s demo data.Feel free to create,update and delete your own data.');
exit;
}
$tracksDeleted = true;
$album_id = $album->id;
$tracks = Track::model()->findAllByAttributes(array('album_id' => $album_id));
foreach ($tracks as $track) {
$deleted = $track->delete();
$tracksDeleted = $tracksDeleted && $deleted;
}
if (!$album->delete()) {
throw new CHttpException(500, 'Could not delete model');
}
if (!$tracksDeleted) {
throw new CHttpException(500, 'Some artist\'s albums were not deleted');
}
if (!$this->unlinkAlbumFromArtist($album_id)) {
throw new CHttpException(500, 'Album was not unlinked from artist.');
}
return $album;
});
}