/** * Load pages user is allowed to access and set the collection as 'pages' relation * */ protected function loadPages() { $pages = Page::join('page_role as pr', 'pr.page_id', '=', 'pages.id')->join('role_user as ru', 'ru.role_id', '=', 'pr.role_id')->where('ru.user_id', $this->id)->distinct()->get(['pages.*', 'user_id']); $hasMany = new Illuminate\Database\Eloquent\Relations\HasMany(Page::query(), $this, 'user_id', 'id'); $hasMany->matchMany([$this], $pages, 'pages'); // If there is no collection to set the relation on, create a blank one if (!isset($this->pages)) { $this->setRelation('pages', new Collection()); } return $this; }
<?php require_once "../web.config.php"; require_once $realLibPath . "model/page.model.php"; $page = new Page(); $id = $_POST['id']; $dataArray = current($page->query(array("ID" => $id), array())); @($currentPage = $_POST['currentPage']); ?> <ol class="am-breadcrumb am-breadcrumb-slash"> <li><a href="#"><strong>页面</strong></a></li> <li><a href="#">编辑</a></li> </ol> <div class="am-form am-form-horizontal"> <div class="am-form-group" style="height:40px"> <label class="am-u-md-2 am-u-md-offset-3 am-form-label am-text-center" >页面标题:</label> <div class="am-u-md-3 am-u-end"> <input type="text" value="<?php echo $dataArray['title']; ?> " id="page_edit_title"/> </div> </div> <div class="am-form-group" style="height:40px"> <label class="am-u-md-2 am-u-md-offset-3 am-form-label am-text-center" >页面类别:</label> <div class="am-u-md-3 am-u-end"> <select name="test" id="page_edit_catID"> <?php foreach ($page->getPageCatInfo() as $item) { ?>
public static function init($items, $per_page = 25, $key = 'pg') { // load the class properties self::$key = $key; self::$perpage = $per_page; self::$items = $items; self::$query = $_GET; self::$script_url = self::current_url(); // determine what page we are on foreach (explode('/', self::$script_url) as $segment) { list($pg, $num) = explode(':', $segment); if ($pg == $key && (int) $num > 0) { self::$current = (int) $num; break; } } if (self::$current <= 0) { self::$current = 1; } // run the page calculations self::$pages = self::$items > 0 ? (int) ceil(self::$items / $per_page) : 1; self::$offset = (self::$current - 1) * $per_page; // redirect to the first page if the page no. is out of range if (self::$current > self::$pages || self::$current < 1) { die(self::get_url(1)); self::redirect(self::get_url(1)); } // load the config file if present if (file_exists(APPPATH . 'config/pagination' . EXT)) { include APPPATH . 'config/pagination' . EXT; # enclosing markup if (isset($config['full_tag_open'])) { self::$full_tag_open = $config['full_tag_open']; } if (isset($config['full_tag_close'])) { self::$full_tag_close = $config['full_tag_close']; } # first link if (isset($config['first_link'])) { self::$first_link = $config['first_link']; } if (isset($config['first_tag_open'])) { self::$first_tag_open = $config['first_tag_open']; } if (isset($config['first_tag_close'])) { self::$first_tag_close = $config['first_tag_close']; } # last link if (isset($config['last_link'])) { self::$last_link = $config['last_link']; } if (isset($config['last_tag_open'])) { self::$last_tag_open = $config['last_tag_open']; } if (isset($config['last_tag_close'])) { self::$last_tag_close = $config['last_tag_close']; } # next link if (isset($config['next_link'])) { self::$next_link = $config['next_link']; } if (isset($config['next_tag_open'])) { self::$next_tag_open = $config['next_tag_open']; } if (isset($config['next_tag_close'])) { self::$next_tag_close = $config['next_tag_close']; } # previous link if (isset($config['prev_link'])) { self::$prev_link = $config['prev_link']; } if (isset($config['prev_tag_open'])) { self::$prev_tag_open = $config['prev_tag_open']; } if (isset($config['prev_tag_close'])) { self::$prev_tag_close = $config['prev_tag_close']; } # current page if (isset($config['cur_tag_open'])) { self::$cur_tag_open = $config['cur_tag_open']; } if (isset($config['cur_tag_close'])) { self::$cur_tag_close = $config['cur_tag_close']; } # digit link if (isset($config['num_tag_open'])) { self::$num_tag_open = $config['num_tag_open']; } if (isset($config['num_tag_close'])) { self::$num_tag_close = $config['num_tag_close']; } } }