本文整理汇总了PHP中ORM类的典型用法代码示例。如果您正苦于以下问题:PHP ORM类的具体用法?PHP ORM怎么用?PHP ORM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ORM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadORM
public function loadORM(ORM $obj, $namespace = null)
{
$this->setElementsBelongTo(lcfirst($namespace));
$fields = $obj->ormFields();
foreach ($fields as $field) {
if ($obj->legacyORMNaming) {
$field = preg_replace_callback('/_(.)/', create_function('$matches', 'return strtoupper($matches[1]);'), $field);
}
if (!is_object($obj->{$field})) {
if (preg_match('/^date.*/', $field)) {
$element = $this->createElement('dateText', $field, array('label' => $this->_prettyName($field)));
} elseif (preg_match('/.*_id$/', $field)) {
$element = $this->createElement('hidden', $field, array('label' => $this->_prettyName($field)));
} else {
$element = $this->createElement('text', $field, array('label' => $this->_prettyName($field)));
}
$element->setValue($obj->{$field});
$this->addElement($element);
} elseif ($obj->{$field} instanceof ORM) {
$sf = new WebVista_Form();
$this->addSubForm($sf, "form" . ucwords($field));
$sf->loadORM($obj->{$field}, $namespace . '[' . lcfirst($field) . ']');
}
}
}
示例2: update
/**
* Function for easy update a ORM object
*
* @param ORM $object ORM object to update
* @param array $messages Array of custom messages
*/
public function update(ORM $object, array $messages = array())
{
// Check if is a valid object
if (!$object->loaded()) {
Messages::warning(isset($messages['warning']) ? $messages['warning'] : 'El elemento que intentas modificar no existe o fue eliminado.');
$this->go();
}
// Only if Request is POST
if ($this->request->method() == Request::POST) {
// Catch ORM_Validation
try {
// Set object values and update
$object->values($this->request->post())->update();
// If object is saved....
if ($object->saved()) {
// Success message & redirect
Messages::success(isset($messages['success']) ? $messages['success'] : 'El elemento fue modificado correctamente.');
$this->go();
}
} catch (ORM_Validation_Exception $e) {
// Error message
if (isset($messages['error'])) {
Messages::error($messages['error']);
}
// Validation messages
Messages::validation($e);
}
}
}
示例3: change_status
public function change_status(ORM $item)
{
if ($item->status) {
$item->status = false;
} else {
$item->status = true;
}
$item->save();
}
示例4: set_model
protected function set_model($model)
{
$this->_model = $model;
if ($this->_model instanceof CM_ModelContainer_Interface) {
$this->_model = $this->_model->get_model();
}
if (!$this->_model instanceof ORM) {
throw new Exception('model must be an instance of ORM');
}
}
示例5: change_status
public function change_status(ORM $item)
{
switch ($item->status) {
case 'open':
$item->status = 'in_process';
break;
case 'in_process':
$item->status = 'closed';
break;
case 'closed':
$item->status = 'open';
break;
}
$item->save();
}
示例6: __construct
public function __construct(ORM $orm, array $columns = array(), $options = array())
{
$this->_options = $options;
$this->set_name($orm->object_name());
foreach ($columns as $name => $column) {
if (!is_array($column)) {
$column = array('type' => $column);
}
$column_cfg = array('name' => $name, 'header' => Arr::get($orm->labels(), $name), 'params' => Arr::get($column, 'params', array()));
$column = Arr::merge($column_cfg, (array) $column);
$column = Grid_Column::factory($column);
$this[$name] = $column;
}
$this->_orm = $orm;
}
示例7: before
public function before()
{
if ($this->auto_render) {
$hostArr = explode('.', $_SERVER['HTTP_HOST']);
$preDomain = $hostArr[0];
$site = ORM::factory('Site')->where('domain', '=', $preDomain)->find();
if ($site->loaded()) {
$this->siteId = $site->id;
$this->category = ORM::factory('Category')->getAll($site->id, Model_Category::STATUS_SHOW);
$site = $site->as_array();
$site['logo'] = '/media/image/data/' . $site['logo'];
$site['category'] = $this->category;
$site['author'] = '简站(Simple-Site.cn) - 免费建站、微信网站、免费微信网站!';
$site['copyright'] = 'Copyright © 2015 SimpleSite. All Rights Reserved';
$site['friendLinks'] = ORM::factory('FriendLink')->getAll($site['id']);
$this->theme = "themes/{$site['theme']}/";
$this->template = View::factory($this->theme . 'base');
foreach ($site as $key => $value) {
View::bind_global($key, $site[$key]);
}
} else {
echo '404';
exit;
}
}
}
示例8: action_index
public function action_index()
{
$photos = ORM::factory('Storage')->where('publication_id', '>', '0')->find_all();
foreach ($photos as $photo) {
if ($photo->publication_type == 'news') {
$news = ORM::factory('News', $photo->publication_id);
if ($news->loaded()) {
$title = $news->title;
}
} elseif ($photo->publication_type == 'leader') {
$page = ORM::factory('Leader', $photo->publication_id);
if ($page->loaded()) {
$title = $page->name;
}
} else {
$page = ORM::factory('Pages_content', $photo->publication_id);
if ($page->loaded()) {
$title = $page->name;
}
}
if (!isset($title)) {
$title = I18n::get("This publication is absent");
}
$photo_arr[] = array('date' => $photo->date, 'path' => $photo->file_path, 'publication_id' => $photo->publication_id, 'type' => $photo->publication_type, 'title' => $title);
}
$this->set('photos', $photo_arr);
$this->add_cumb('Photos', '/');
}
示例9: get_findOrederName
public function get_findOrederName()
{
$PDO_coupon = ORM::factory('Coupons')->PDO();
$query = "SELECT orders.name, orders.id\n FROM orders\n WHERE orders.id = '{$this->order_id}'";
$result = $PDO_coupon->query($query)->fetch();
return $result['name'];
}
示例10: index
public function index()
{
// Get all active scheduled items
foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
$scheduler_id = $scheduler->id;
$scheduler_last = $scheduler->scheduler_last;
// Next run time
$scheduler_weekday = $scheduler->scheduler_weekday;
// Day of the week
$scheduler_day = $scheduler->scheduler_day;
// Day of the month
$scheduler_hour = $scheduler->scheduler_hour;
// Hour
$scheduler_minute = $scheduler->scheduler_minute;
// Minute
// Controller that performs action
$scheduler_controller = $scheduler->scheduler_controller;
if ($scheduler_day <= -1) {
// Ran every day?
$scheduler_day = "*";
}
if ($scheduler_weekday <= -1) {
// Ran every day?
$scheduler_weekday = "*";
}
if ($scheduler_hour <= -1) {
// Ran every hour?
$scheduler_hour = "*";
}
if ($scheduler_minute <= -1) {
// Ran every minute?
$scheduler_minute = "*";
}
$scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
//Start new cron parser instance
$cron = new CronParser($scheduler_cron);
$lastRan = $cron->getLastRan();
//Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
$cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
if (!($scheduler_last > $cronRan - 45) || $scheduler_last == 0) {
// within 45 secs of cronRan time, so Execute control
$site_url = "http://" . $_SERVER['SERVER_NAME'] . "/";
$scheduler_status = remote::status($site_url . "scheduler/" . $scheduler_controller);
// Set last time of last execution
$schedule_time = time();
$scheduler->scheduler_last = $schedule_time;
$scheduler->save();
// Record Action to Log
$scheduler_log = new Scheduler_Log_Model();
$scheduler_log->scheduler_id = $scheduler_id;
$scheduler_log->scheduler_name = $scheduler->scheduler_name;
$scheduler_log->scheduler_status = $scheduler_status;
$scheduler_log->scheduler_date = $schedule_time;
$scheduler_log->save();
}
}
Header("Content-Type: image/gif");
// Transparent GIF
echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
}
示例11: stats
static function stats()
{
$remaining = db::build()->from("items")->join("search_records", "items.id", "search_records.item_id", "left")->and_open()->where("search_records.item_id", "IS", null)->or_where("search_records.dirty", "=", 1)->close()->count_records();
$total = ORM::factory("item")->count_all();
$percent = round(100 * ($total - $remaining) / $total);
return array($remaining, $total, $percent);
}
示例12: feed
static function feed($feed_id, $offset, $limit, $id)
{
$feed = new stdClass();
switch ($feed_id) {
case "latest":
$feed->items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC")->find_all($limit, $offset);
$all_items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC");
$feed->max_pages = ceil($all_items->find_all()->count() / $limit);
$feed->title = t("%site_title - Recent updates", array("site_title" => item::root()->title));
$feed->description = t("Recent updates");
return $feed;
case "album":
$item = ORM::factory("item", $id);
access::required("view", $item);
$feed->items = $item->viewable()->descendants($limit, $offset, array(array("type", "=", "photo")));
$feed->max_pages = ceil($item->viewable()->descendants_count(array(array("type", "=", "photo"))) / $limit);
if ($item->id == item::root()->id) {
$feed->title = html::purify($item->title);
} else {
$feed->title = t("%site_title - %item_title", array("site_title" => item::root()->title, "item_title" => $item->title));
}
$feed->description = nl2br(html::purify($item->description));
return $feed;
}
}
示例13: print_proxy
public function print_proxy($site_key, $file_id)
{
// This function retrieves the full-sized image for fotomoto.
// As this function by-passes normal Gallery security, a private
// site-key is used to try and prevent people other then fotomoto
// from finding the URL.
// If the site key doesn't match, display a 404 error.
if ($site_key != module::get_var("fotomotorw", "fotomoto_private_key")) {
throw new Kohana_404_Exception();
}
// Load the photo from the provided id. If the id# is invalid, display a 404 error.
$item = ORM::factory("item", $file_id);
if (!$item->loaded()) {
throw new Kohana_404_Exception();
}
// If the image file doesn't exist for some reason, display a 404 error.
if (!file_exists($item->file_path())) {
throw new Kohana_404_Exception();
}
// Display the image.
header("Content-Type: {$item->mime_type}");
Kohana::close_buffers(false);
$fd = fopen($item->file_path(), "rb");
fpassthru($fd);
fclose($fd);
}
示例14: album_menu
static function album_menu($menu, $theme)
{
$descendants_count = ORM::factory("item", $theme->item()->id)->descendants_count(array("type" => "photo"));
if ($descendants_count > 1) {
$menu->append(Menu::factory("link")->id("slideshow")->label(t("View slideshow"))->url("javascript:cooliris.embed.show(" . "{maxScale:0,feed:'" . self::_feed_url($theme) . "'})")->css_id("g-slideshow-link"));
}
}
示例15: create_comment_for_user_test
public function create_comment_for_user_test()
{
$rand = rand();
$root = ORM::factory("item", 1);
$admin = user::lookup(2);
$comment = comment::create($root, $admin, "text_{$rand}", "name_{$rand}", "email_{$rand}", "url_{$rand}");
$this->assert_equal($admin->full_name, $comment->author_name());
$this->assert_equal($admin->email, $comment->author_email());
$this->assert_equal($admin->url, $comment->author_url());
$this->assert_equal("text_{$rand}", $comment->text);
$this->assert_equal(1, $comment->item_id);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept);
$this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset);
$this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding);
$this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language);
$this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection);
$this->assert_equal("HTTP_HOST", $comment->server_http_host);
$this->assert_equal("HTTP_REFERER", $comment->server_http_referer);
$this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
$this->assert_equal("QUERY_STRING", $comment->server_query_string);
$this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
$this->assert_equal("REMOTE_HOST", $comment->server_remote_host);
$this->assert_equal("REMOTE_PORT", $comment->server_remote_port);
$this->assert_true(!empty($comment->created));
}