本文整理汇总了PHP中Message::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::instance方法的具体用法?PHP Message::instance怎么用?PHP Message::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
public function action_index($identifier = false)
{
// TODO: cache this crap
if (!$identifier) {
Message::instance()->set('No user specified.');
return $this->request->redirect('');
}
if (is_numeric($identifier)) {
// pass
$user = ORM::factory('user', $identifier);
} else {
$user = ORM::factory('user')->where('username', '=', $identifier)->find();
}
if ($user->loaded()) {
$user = (object) $user->as_array();
unset($user->password);
$user->avatar = Gravatar::avatar($user->email, 128);
unset($user->email);
$this->template->user = $user;
$pg = isset($_GET['p']) && (int) $_GET['p'] ? $_GET['p'] : 1;
$pg = max($pg, 1);
$l = 10;
$q = array('user' => $user->id, 'l' => $l, 'o' => ($pg - 1) * $l, 'p' => $pg, 'recent' => 'yes');
$r = Sourcemap_Search::find($q);
$this->template->search_result = $r;
$p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic'));
$this->template->pager = $p;
$this->template->supplychains = $r->results;
} else {
Message::instance()->set('That user doesn\'t exist.');
return $this->request->redirect('');
}
}
示例2: singleton
public static function singleton()
{
if (!isset(self::$instance)) {
self::$instance = new Message();
}
return self::$instance;
}
示例3: action_index
public function action_index($supplychain_id)
{
if (!is_numeric($supplychain_id)) {
$supplychain_id = $this->_match_alias($supplychain_id);
}
$supplychain = ORM::factory('supplychain', $supplychain_id);
$sc = $supplychain->kitchen_sink($supplychain_id);
if ($supplychain->loaded()) {
$current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0;
$owner_id = (int) $supplychain->user_id;
if ($supplychain->user_can($current_user_id, Sourcemap::READ)) {
$this->layout->supplychain_id = $supplychain_id;
// pass supplychain metadeta to template
$this->template->supplychain_id = $supplychain_id;
$this->template->supplychain_date = date('F j, Y', $sc->created);
$this->template->supplychain_name = isset($sc->attributes->name) ? $sc->attributes->name : "";
$this->template->supplychain_owner = isset($sc->owner->name) ? $sc->owner->name : "";
$this->template->supplychain_ownerid = isset($sc->owner->id) ? $sc->owner->id : "";
$this->template->supplychain_avatar = isset($sc->owner->avatar) ? $sc->owner->avatar : "";
$this->template->supplychain_desc = isset($sc->attributes->description) ? $sc->attributes->description : "";
$this->layout->scripts = array('blog-view');
$this->layout->styles = array('sites/default/assets/styles/reset.css', 'assets/styles/base.less', 'assets/styles/general.less');
// qrcode url
$qrcode_query = URL::query(array('q' => URL::site('view/' . $supplychain->id, true), 'sz' => 8));
$this->template->qrcode_url = URL::site('services/qrencode', true) . $qrcode_query;
} else {
Message::instance()->set('That map is private.');
$this->request->redirect('browse');
}
} else {
Message::instance()->set('That map could not be found.');
$this->request->redirect('browse');
}
}
示例4: action_edit
/**
* Page editor
*/
public function action_edit()
{
Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Admin_Page::action_edit');
$this->template->content = View::factory('cms/pages/form')->bind('legend', $legend)->set('submit', __('Save'))->bind('page', $this->_resource)->bind('errors', $errors);
// Bind locally
$page =& $this->_resource;
$legend = __('Edit :title', array(':title' => $page->title));
if ($_POST) {
$page->values($_POST);
$page->editor = $this->a1->get_user()->id;
try {
$page->update();
Message::instance()->info('The page, :title, has been updated.', array(':title' => $page->title));
if (!$this->_internal) {
$this->request->redirect($this->request->uri(array('action' => 'list')));
}
} catch (Validate_Exception $e) {
$errors = $e->array->errors('admin');
}
}
// Set template scripts and styles
$this->template->scripts[] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js';
$this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/jquery.markitup.js'));
$this->template->scripts[] = Route::get('media')->uri(array('file' => 'js/markitup/sets/html/set.js'));
$this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/skins/markitup/style.css'))] = 'screen';
$this->template->styles[Route::get('media')->uri(array('file' => 'js/markitup/sets/html/style.css'))] = 'screen';
}
示例5: getInstace
public static function getInstace()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
示例6: action_index
public function action_index()
{
$supplychain_alias = ORM::factory('supplychain_alias');
$page = max($this->request->param('page'), 1);
$items = 20;
$offset = $items * ($page - 1);
$count = $supplychain_alias->count_all();
$pagination = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'page'), 'total_items' => $supplychain_alias->count_all(), 'items_per_page' => $items));
$this->template->supplychain_alias = $supplychain_alias->limit($pagination->items_per_page)->offset($pagination->offset)->find_all()->as_array(null, array('id', 'site', 'alias', 'supplychain_id'));
$this->template->page_links = $pagination->render();
$this->template->offset = $pagination->offset;
$supplychain_alias_count = $supplychain_alias->count_all();
$post = Validate::factory($_POST);
$post->rule('site', 'not_empty')->rule('alias', 'not_empty')->filter('site', 'strip_tags')->filter('alias', 'strip_tags')->rule('supplychain_id', 'not_empty')->filter(true, 'trim');
if (strtolower(Request::$method) === 'post' && $post->check()) {
$check = false;
$post = (object) $post->as_array();
$site_added = $post->site;
$alias_added = $post->alias;
$id = $post->supplychain_id;
// check if the alias already exists, if not add new alias
$supplychain_alias = ORM::factory('supplychain_alias');
$supplychain_alias->supplychain_id = $id;
$supplychain_alias->site = $site_added;
$supplychain_alias->alias = $alias_added;
try {
$supplychain_alias->save();
} catch (Exception $e) {
Message::instance()->set('Could not create alias. Violates the unique (site, alias)');
}
$this->request->redirect('admin/aliases');
}
Breadcrumbs::instance()->add('Management', 'admin/')->add('Aliases', 'admin/aliases');
}
示例7: getInstance
public static function getInstance()
{
$config = Config::getInstance()->getConfigurations();
if (!isset(self::$instance)) {
self::$instance = new Message($config['language']);
}
return self::$instance;
}
示例8: action_logout
/**
* Perform user logout
*/
public function action_logout()
{
Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Auth::action_logout');
$this->a1->logout();
Kohana::$log->add('ACCESS', 'Successful logout made by user.');
Message::instance()->info(Kohana::message('a2', 'logout.success'));
if (!$this->_internal) {
$this->request->redirect(Route::get('admin')->uri());
}
}
示例9: action_index
public function action_index()
{
$this->layout->page_title = 'Create a supply chain';
$f = Sourcemap_Form::load('/create');
$f->action('create')->method('post');
if (!Auth::instance()->get_user()) {
$this->request->redirect('auth');
}
$this->layout->scripts = array('sourcemap-core', 'sourcemap-template');
$import_role = ORM::factory('role')->where('name', '=', 'import')->find();
$admin_role = ORM::factory('role')->where('name', '=', 'admin')->find();
if (Auth::instance()->get_user()->has('roles', $import_role) || Auth::instance()->get_user()->has('roles', $admin_role)) {
$this->template->can_import = true;
} else {
$this->template->can_import = false;
}
$this->template->create_form = $f;
if (strtolower(Request::$method) === 'post') {
if ($f->validate($_POST)) {
// create!
$p = $f->values();
$title = $p['title'];
$description = substr($p['description'], 0, 80);
$tags = Sourcemap_Tags::join(Sourcemap_Tags::parse($p['tags']));
$category = $p['category'];
$public = isset($_POST['publish']) ? Sourcemap::READ : 0;
$raw_sc = new stdClass();
if ($category) {
$raw_sc->category = $category;
}
$raw_sc->attributes = new stdClass();
$raw_sc->attributes->title = $title;
$raw_sc->attributes->description = $description;
$raw_sc->attributes->tags = $tags;
$raw_sc->stops = array();
$raw_sc->hops = array();
$raw_sc->user_id = Auth::instance()->get_user()->id;
$raw_sc->other_perms = 0;
if ($public) {
$raw_sc->other_perms |= $public;
} else {
$raw_sc->other_perms &= ~Sourcemap::READ;
}
try {
$new_scid = ORM::factory('supplychain')->save_raw_supplychain($raw_sc);
return $this->request->redirect('view/' . $new_scid);
} catch (Exception $e) {
$this->request->status = 500;
Message::instance()->set('Couldn\\t create your supplychain. Please contact support.');
}
} else {
Message::instance()->set('Correct the errors below.');
}
}
}
示例10: action_delete_role_entry
public function action_delete_role_entry($id)
{
$role = ORM::factory('role', $id);
try {
$role->delete();
Message::instance()->set('Role deleted.');
} catch (Exception $e) {
Message::instance()->set('Role could not be deleted.');
}
$this->request->redirect("admin/roles/");
}
示例11: before
public function before()
{
$this->current_user = Auth::instance()->get_user();
$admin = ORM::factory('role')->where('name', '=', 'admin')->find();
if ($this->current_user && $this->current_user->has('roles', $admin)) {
// pass
} else {
Message::instance()->set('You\'re not allowed to access the management dashboard.', Message::ERROR);
$this->request->redirect('auth');
}
parent::before();
$this->layout->page_title = 'Management';
}
示例12: action_index
public function action_index($supplychain_id = false)
{
if (!$supplychain_id) {
$this->request->redirect('home');
}
if (!is_numeric($supplychain_id)) {
$supplychain_id = $this->_match_alias($supplychain_id);
}
$supplychain = ORM::factory('supplychain', $supplychain_id);
if ($supplychain->loaded()) {
$current_user_id = Auth::instance()->logged_in() ? (int) Auth::instance()->get_user()->id : 0;
$owner_id = (int) $supplychain->user_id;
if ($current_user_id && $supplychain->user_can($current_user_id, Sourcemap::WRITE)) {
$supplychain = $supplychain->kitchen_sink($supplychain->id);
$this->layout->page_title = 'Delete a supply chain';
// create the form object and add fields
$form = Sourcemap_Form::factory('delete')->method('post')->action('delete/' . $supplychain_id)->add_class('vertical')->select('confirm_once', 'Are you sure?')->select('confirm_twice', 'We can\'t undo this. Are you still sure you want to delete this map?')->select('confirm_thrice', 'Seriously. This is a permanent thing. Are you *sure*?')->submit('delete', 'Delete');
$form->field('confirm_once')->option('no', 'No')->option('yes', 'Yes');
$form->field('confirm_twice')->option('no', 'No')->option('yes', 'Yes');
$form->field('confirm_thrice')->option('no', 'No')->option('yes', 'Yes');
if (strtolower(Request::$method) === 'post') {
$post = Validate::factory($_POST);
$post->rule('confirm_once', 'in_array', array(array('yes')))->rule('confirm_twice', 'in_array', array(array('yes')))->rule('confirm_thrice', 'in_array', array(array('yes')));
if ($post->check()) {
try {
ORM::factory('supplychain', $supplychain->id)->delete();
Message::instance()->set('Map deleted.', Message::SUCCESS);
return $this->request->redirect('home');
} catch (Exception $e) {
$this->request->status = 500;
Message::instance()->set('Couldn\'t delete your supplychain. Please contact support.');
}
} else {
Message::instance()->set('You don\'t seem sure.');
$form->errors($post->errors('forms/create'));
}
}
$this->template->supplychain = $supplychain;
$this->template->form = $form;
} else {
Message::instance()->set('You\'re not allowed to edit that map.');
$this->request->redirect('home');
}
} else {
Message::instance()->set('That map does not exist.');
$this->request->redirect('home');
}
}
示例13: action_remove
public function action_remove($id)
{
$sc = ORM::factory('supplychain', $id);
if ($sc->loaded()) {
$sc->flags = $sc->flags & ~Sourcemap::FEATURED;
$sc->save();
if (Sourcemap_Search_Index::should_index($sc->id)) {
Sourcemap_Search_Index::update($sc->id);
}
Message::instance()->set('Unfeatured map.', Message::SUCCESS);
$this->request->redirect('admin/featured');
} else {
Message::instance()->set('That supplychain does not exist.');
$this->request->redirect('admin/featured');
}
}
示例14: action_index
public function action_index($category = false)
{
$this->layout->scripts = array('sourcemap-core');
$this->layout->page_title = 'Browsing supply chains';
$cats = Sourcemap_Taxonomy::arr();
$nms = array();
foreach ($cats as $i => $cat) {
$nms[Sourcemap_Taxonomy::slugify($cat->name)] = $cat;
}
$this->template->taxonomy = Sourcemap_Taxonomy::load_tree();
$defaults = array('q' => false, 'p' => 1, 'l' => 20);
$params = $_GET;
if (strtolower(Request::$method) == 'post') {
$params = $_POST;
}
$params = array_merge($defaults, $params);
$params['recent'] = 'yes';
$params['l'] = 20;
if ($category && isset($nms[$category])) {
$slug = $category;
$category = $nms[$category];
$this->template->category = $category;
$params['c'] = $category->name;
$this->layout->page_title .= ' - ' . $category->title;
} elseif ($category) {
Message::instance()->set('"' . $category . '" is not a valid category slug.');
return $this->request->redirect('browse');
} else {
$this->template->category = false;
}
$r = Sourcemap_Search::find($params);
$p = Pagination::factory(array('current_page' => array('source' => 'query_string', 'key' => 'p'), 'total_items' => $r->hits_tot, 'items_per_page' => $r->limit, 'view' => 'pagination/basic'));
$this->template->primary = $r;
$this->template->pager = $p;
$params['l'] = 1;
$this->template->favorited = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes'));
$this->template->discussed = Sourcemap_Search_Simple::find($params + array('comments' => 'yes'));
$this->template->interesting = Sourcemap_Search_Simple::find($params + array('favorited' => 'yes', 'comments' => 'yes'));
$this->template->recent = Sourcemap_Search_Simple::find($params + array('recent' => 'yes'));
}
示例15: action_add
public function action_add()
{
$post = Validate::factory($_POST)->rule('user_id', 'not_empty');
if ($post->check()) {
$user_id = $post['user_id'];
$user = ORM::factory('user', $user_id);
if ($user->loaded()) {
$newkey = md5(sprintf('%s-%s-%s', $user->id, $user->email, microtime()));
$newsecret = md5(sprintf('%s-%s-%s-%s', microtime(), $user->email, $user->id, $newkey));
$apikey = ORM::factory('user_apikey');
$apikey->apikey = $newkey;
$apikey->apisecret = $newsecret;
$apikey->user_id = $user->id;
$apikey->save();
Message::instance()->set(sprintf('Added api key for "%s".', $user->username));
} else {
Message::instance()->set('Could not add api key: invalid user.', Message::ERROR);
}
} else {
Message::instance()->set('Missing or invalid user id.', Message::ERROR);
}
$this->request->redirect('admin/apikeys');
}