本文整理汇总了PHP中Jelly::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::factory方法的具体用法?PHP Jelly::factory怎么用?PHP Jelly::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create
public function action_create()
{
// Check if the user has a character already.
if ($this->character->loaded()) {
$this->request->redirect('character/create');
}
$character = Jelly::factory('character');
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('name', 'not_empty')->rule('name', 'min_length', array(3))->rule('name', 'max_length', array(20))->rule('gender', 'not_empty')->rule('race', 'not_empty')->callback('race', array($this, 'valid_race'));
if ($post->check()) {
try {
$values = array('name' => $post['name'], 'gender' => $post['gender'], 'race' => $post['race'], 'user' => $this->user->id, 'money' => 1000, 'hp' => 100, 'max_hp' => 100, 'level' => 1, 'xp' => 0, 'energy' => 100, 'alignment' => 5000, 'zone' => 1);
$character->set($values);
$character->save();
$this->MG->add_history('Created the character: ' . $post['name']);
$this->request->redirect('character');
} catch (Validate_Exception $e) {
// Get the errors using the Validate::errors() method
$this->errors = $e->array->errors('register');
}
} else {
$this->errors = $post->errors('character/create');
}
// Get the races the user can choose from.
$races = $this->getRaces();
$this->template->content = View::factory('character/create')->set('post', $post)->set('races', $races);
}
示例2: action_add
public function action_add($id)
{
// Find the parent
$parent = Jelly::select('kohanut_page', $id);
if (!$parent->loaded()) {
return $this->admin_error(__('Could not find page with ID :id.', array(':id' => $id)));
}
// Create the new page object
$page = Jelly::factory('kohanut_page');
// Create the view
$this->view->title = __('Adding New Page');
$this->view->body = new View('kohanut/pages/add', array('errors' => false, 'success' => false, 'parent' => $parent, 'page' => $page));
if ($_POST) {
try {
$page->set($_POST);
$page->create_at($parent, Arr::get($_POST, 'location', 'last'));
// Page was created successfully, redirect to edit
$this->request->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'pages', 'action' => 'edit', 'params' => $page->id)));
} catch (Validate_Exception $e) {
$this->view->body->errors = $e->array->errors('page');
} catch (Kohanut_Exception $e) {
$this->view->body->errors = array($e->getMessage());
}
}
}
示例3: action_register
public function action_register()
{
if ($this->user) {
Request::instance()->redirect('');
}
// Experimental facebook connection
$this->facebook = new Fb();
// User accessed from facebook!
if ($this->facebook->validate_fb_params()) {
$this->facebook->require_frame();
$_SESSION['fb_uid'] = $this->facebook->require_login();
} elseif (!isset($_SESSION['fb_uid'])) {
Request::instance()->redirect('');
}
// Check if the user got an account.
$user_facebook = Jelly::select('user_facebook')->where('facebook_id', '=', $_SESSION['fb_uid'])->load();
// If we found it, log him in.
if ($user_facebook->loaded()) {
$this->a1->force_login($user_facebook->user->username);
$_SESSION['facebook'] = 'TRUE';
// Used for verifying if logged in using facebook.
Request::instance()->redirect('');
}
$user = Jelly::factory('user');
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(3))->rule('username', 'max_length', array(20))->rule('username', 'alpha_numeric')->rule('email', 'email')->rule('tos', 'not_empty');
if ($post->check()) {
$values = array('username' => $post['username'], 'email' => $post['email']);
// Assign the validated data to the sprig object
$user->set($values);
// Hash the password
$user->password = '';
// Set the default role for registered user.
$user->role = 'facebook';
try {
// Create the new user
$testy = $user->save();
//print_r($testy);
$user_id = mysql_insert_id();
$ufb = Jelly::factory('user_facebook');
$ufb->facebook_id = $_SESSION['fb_uid'];
$ufb->user = $user_id;
$ufb->save();
$this->a1->force_login($values['username']);
$_SESSION['facebook'] = 'TRUE';
// Used for verifying if logged in using facebook.
// Redirect the user to the login page
$this->request->redirect('');
} catch (Validate_Exception $e) {
// Get the errors using the Validate::errors() method
$this->errors = $e->array->errors('register');
}
} else {
$this->errors = $post->errors('account/register');
}
if (!empty($this->errors)) {
Message::set(Message::ERROR, $this->errors);
}
$this->template->content = View::factory('facebook/register')->set('post', $post->as_array());
}
示例4: action_create
public function action_create()
{
$this->content->bind('form', $supply);
// uzywajac bind() widok zapamieta referencje a nie wartosc
$this->content->bind('suppliers', $suppliers);
$this->content->bind('errors', $errors);
// czyli: jesli zmienimy tutaj wartosc zmiennych $supply
// lub $error to bedzie to w widoku te zmienne tez beda zmienione
$supply = Jelly::factory('supply');
$id = $this->request->param('id');
$supply->product = Jelly::select('product', $id);
if (!$supply->product->loaded()) {
$this->request->redirect($this->_base);
}
if ($_POST and !$this->session->get($_POST['seed'], FALSE)) {
try {
$supply->set($_POST);
$supply->save();
$this->session->set($_POST['seed'], TRUE);
// 'seed' jest zintegrowany w formularz
$this->request->redirect($this->_base);
} catch (Validate_Exception $e) {
$errors = $e->errors();
}
}
}
示例5: action_reply
/**
* Create a new post.
*/
public function action_reply($id)
{
$topic = Jelly::select('forum_topic')->where('id', '=', $id)->load();
// Make sure the topic exists
if (!$topic->loaded()) {
Message::set(Message::ERROR, 'Topic does not exist');
$this->request->redirect('forum');
}
$this->title = 'Forum - Reply to ' . $topic->title;
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
if ($post->check()) {
$values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $id);
$message = Jelly::factory('forum_post');
// Assign the validated data to the Jelly object
$message->set($values);
$message->save();
$topic_id = $id;
$topic = Jelly::select('forum_topic')->where('id', '=', $topic_id)->load();
$topic->posts = $topic->posts + 1;
$topic->save();
Message::set(Message::SUCCESS, 'You posted a new reply.');
$this->request->redirect('forum/topic/' . $id);
} else {
$this->errors = $post->errors('forum');
}
if (!empty($this->errors)) {
Message::set(Message::ERROR, $this->errors);
}
$this->template->content = View::factory('forum/post/create')->set('post', $post->as_array());
}
示例6: action_new_topic
/**
* Create a new topic.
*/
public function action_new_topic($id)
{
$this->title = 'Forum - New Topic';
$category = Jelly::select('forum_category')->where('id', '=', $id)->load();
if (!$category->loaded()) {
Message::set(Message::ERROR, 'Category does not exist');
$this->request->redirect('forum');
}
// Validate the form input
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->filter(TRUE, 'htmlspecialchars', array(ENT_QUOTES))->rule('title', 'not_empty')->rule('title', 'min_length', array(3))->rule('title', 'max_length', array(20))->rule('content', 'not_empty')->rule('content', 'min_length', array(5))->rule('content', 'max_length', array(1000));
if ($post->check()) {
$topic_values = array('title' => $post['title'], 'user' => $this->user->id, 'category' => $id, 'status' => 'open', 'posts' => '1');
$topic = Jelly::factory('forum_topic');
// Assign the validated data to the sprig object
$topic->set($topic_values);
$topic->save();
$topic_id = $topic->id;
$post_values = array('title' => $post['title'], 'content' => $post['content'], 'user' => $this->user->id, 'topic' => $topic_id);
$message = Jelly::factory('forum_post');
// Assign the validated data to the sprig object
$message->set($post_values);
$message->save();
Message::set(Message::SUCCESS, 'You created a topic.');
$this->request->redirect('forum/category/' . $id);
} else {
$this->errors = $post->errors('forum');
}
if (!empty($this->errors)) {
Message::set(Message::ERROR, $this->errors);
}
$this->template->content = View::factory('forum/topic/create')->set('post', $post->as_array());
}
示例7: before
/**
* Construct controller
*/
public function before()
{
// Log request
Jelly::factory('api_request')->set(array('ip' => Request::$client_ip, 'request' => $this->request->uri . (empty($_GET) ? '' : '?' . http_build_query($_GET))))->save();
// Rate limit
$rate_span = Kohana::config('api.rate_span');
$rate_limit = Kohana::config('api.rate_limit');
$requests = Model_API_Request::request_count(time() - $rate_span, Request::$client_ip);
$requests_left = $rate_limit - $requests;
if ($requests_left < 0) {
throw new Controller_API_Exception('Request limit reached');
}
// Check version
$this->version = $this->request->param('version');
if (!in_array($this->version, self::$_versions)) {
throw new Controller_API_Exception('Invalid version');
}
// Check format
$this->format = $this->request->param('format');
!$this->format and $this->format = self::FORMAT_JSON;
if (!in_array($this->format, self::$_formats)) {
throw new Controller_API_Exception('Invalid format');
}
// Set result defaults
$this->data = array('version' => $this->version, 'requests' => $requests, 'requests_left' => $requests_left, 'request_window' => $rate_span);
return parent::before();
}
示例8: action_register
public function action_register()
{
// There are no errors by default
$errors = FALSE;
// Create an instance of Model_Auth_User
$user = Jelly::factory('user');
// Check if the form was submitted
if ($_POST) {
/**
* Load the $_POST values into our model.
*
* We use Arr::extract() and specify the fields to add
* by hand so that a malicious user can't do (for example)
* `$_POST['roles'][] = 2;` and make themselves an administrator.
*/
$user->set(Arr::extract($_POST, array('email', 'username', 'password', 'password_confirm')));
// Add the 'login' role to the user model
$user->add('roles', 1);
try {
// Try to save our user model
$user->save();
// Redirect to the index page
$this->request->redirect(Route::get('default')->uri(array('action' => 'index')));
} catch (Validate_Exception $e) {
// Load custom error messages from `messages/forms/user/register.php`
$errors = $e->array->errors('forms/user/register');
}
}
// Set template title
$this->template->title = 'Register';
// Display the 'register' template
$this->template->content = View::factory('user/register')->set('user', $user)->set('errors', $errors);
}
示例9: verify
/**
* Verify the Flickr credentials.
*
* @throws Kohana_Exception
* @return boolean
*/
public function verify()
{
// Set the service
$service = $this->_service;
if (empty($service)) {
MMI_Log::log_error(__METHOD__, __LINE__, 'Service not set');
throw new Kohana_Exception('Service not set in :method.', array(':method' => __METHOD__));
}
// Ensure the frob is set
$frob = NULL;
if (array_key_exists('frob', $_GET)) {
$frob = urldecode(Security::xss_clean($_GET['frob']));
}
if (empty($frob)) {
MMI_Log::log_error(__METHOD__, __LINE__, 'Frob parameter missing');
throw new Kohana_Exception('Frob parameter missing in :method.', array(':method' => __METHOD__));
}
// Load existing data from the database
$auth_config = $this->_auth_config;
$username = Arr::get($auth_config, 'username');
$model;
if (!empty($username)) {
$model = Model_MMI_API_Tokens::select_by_service_and_username($service, $username, FALSE);
} else {
$model = Jelly::factory('MMI_API_Tokens');
}
$success = FALSE;
if ($model->loaded()) {
// Check if the credentials were previously verified
$previously_verified = $model->verified;
if ($previously_verified) {
$success = TRUE;
} else {
// Create a dummy verification code
$verification_code = $service . '-' . time();
}
// Do database update
if (!$previously_verified) {
// Get an access token
$svc = MMI_API::factory($service);
$token = $svc->get_access_token($verification_code, array('token_key' => $frob, 'token_secret' => $service . '-' . time()));
// Update the token credentials in the database
if (isset($token) and $svc->is_valid_token($token)) {
$model->token_key = $token->key;
$model->token_secret = Encrypt::instance()->encode($token->secret);
$model->verified = 1;
$model->verification_code = $verification_code;
if (!empty($token->attributes)) {
$model->attributes = $token->attributes;
}
$success = MMI_Jelly::save($model, $errors);
if (!$success and $this->_debug) {
MMI_Debug::dead($errors);
}
}
}
}
return $success;
}
示例10: provider_construction
/**
* Provider for test type
*/
public function provider_construction()
{
// Set database connection name
$db = parent::$database_connection;
// Set result
$result = DB::select()->from('test_posts');
return array(array(new Jelly_Collection($result->execute($db), 'Model_Test_Post'), 'Model_Test_Post'), array(new Jelly_Collection($result->execute($db), Jelly::factory('test_post')), 'Model_Test_Post'), array(new Jelly_Collection($result->execute($db)), FALSE), array(new Jelly_Collection($result->as_object()->execute($db)), 'stdClass'), array(new Jelly_Collection($result->execute($db), 'Model_Test_Post'), 'Model_Test_Post'));
}
示例11: action_view
/**
* Attempt to find a page in the CMS, return the response
*
* @param string The url to load, will be autodetected if needed
* @return void
*/
public function action_view($url = NULL)
{
if (Kohana::$profiling === TRUE) {
// Start a new benchmark
$benchmark = Profiler::start('Kohanut', 'Kohanut Controller');
}
// If no $url is passed, default to the server request uri
if ($url === NULL) {
$url = $_SERVER['REQUEST_URI'];
}
// Trim off Kohana::$base_url
$url = preg_replace('#^' . Kohana::$base_url . '#', '', $url);
// Ensure no trailing slash
$url = preg_replace('/\\/$/', '', $url);
// Ensure no leading slash
$url = preg_replace('/^\\//', '', $url);
// Remove anything ofter a ? or #
$url = preg_replace('/[\\?#].+/', '', $url);
// Try to find what to do on this url
try {
// Make sure the url is clean. See http://www.faqs.org/rfcs/rfc2396.html see section 2.3
// TODO - this needs to be better
if (preg_match("/[^\\/A-Za-z0-9-_\\.!~\\*\\(\\)]/", $url)) {
Kohana::$log->add('INFO', "Kohanut - Request had unknown characters. '{$url}'");
throw new Kohanut_Exception("Url request had unknown characters '{$url}'", array(), 404);
}
// Check for a redirect on this url
Jelly::factory('kohanut_redirect')->set(array('url', $url))->go();
// Find the page that matches this url, and isn't an external link
$page = Jelly::select('kohanut_page')->where('url', '=', $url)->where('islink', '=', 0)->limit(1)->execute();
if (!$page->loaded()) {
// Could not find page in database, throw a 404
Kohana::$log->add('INFO', "Kohanut - Could not find '{$url}' (404)");
throw new Kohanut_Exception("Could not find '{$page->url}'", array(), 404);
}
// Set the status to 200, rather than 404, which was set by the router with the reflectionexception
Kohanut::status(200);
header('Last-Modified: ' . date(DateTime::RFC2822, $page->edited));
$out = $page->render();
} catch (Kohanut_Exception $e) {
// Find the error page
$error = Jelly::select('kohanut_page')->where('url', '=', 'error')->limit(1)->execute();
// If i couldn't find the error page, just give a generic message
if (!$error->loaded()) {
Kohanut::status(404);
$this->request->response = View::factory('kohanut/generic404');
return;
}
// Set the response
$out = $error->render();
}
if (isset($benchmark)) {
// Stop the benchmark
Profiler::stop($benchmark);
}
// Set the response
$this->request->response = $out;
}
示例12: set
public static function set($key, $value, $description = '')
{
$setting = Jelly::select('setting')->where('setting', '=', $key)->limit(1)->execute();
if (!$setting->loaded()) {
Jelly::factory('setting')->set(array('setting' => $key, 'value' => $value, 'description' => $description))->save();
} else {
$setting->value = $value;
$setting->save();
}
}
示例13: save
public function save($model, $value, $loaded)
{
if ($model->price->changed()) {
$values = array('value' => $model->price->value, 'vat' => $model->price->vat);
$price = Jelly::factory('price')->set($values)->save();
$value = $price->id;
$model->_late_update[] = array($price, 'product', 'id');
}
return $value;
}
示例14: action_add_item
public function action_add_item($feed_id)
{
$form = Uniform::factory('Krss_Item');
//check form and feed
if ($form->sent() and $data = $form->bind($_POST)->check() and $feed = Jelly::select('krss_feed', $feed_id) and $feed->loaded()) {
$data['feed'] = $feed;
Jelly::factory('krss_item')->set($data)->save();
$redirect_to = isset($_GET['redirect_to']) ? $_GET['redirect_to'] : KRSS . '/feed/show/' . $feed_id;
Url::redirect($redirect_to);
}
$this->template->content = View::factory('krss/add_item')->set(array('form' => $form));
}
示例15: load_user
/**
* Loading user by name
*
* @param string $username
* @param string $password
* @return object / NULL
*/
public function load_user($username, $password)
{
$user = Jelly::select($this->_config['user_model'])->where($this->_config['columns']['username'], '=', $username)->limit(1)->execute();
if ($user->loaded()) {
return $user;
} else {
// Creating default user
// @todo: move this shit to install method
if (Jelly::select('user')->count() === 0) {
Jelly::factory('user', array('email' => $this->_config['admin']['email'], 'password' => $this->_config['admin']['password'], 'password_confirm' => $this->_config['admin']['password']))->save();
}
return NULL;
}
}