当前位置: 首页>>代码示例>>PHP>>正文


PHP Jelly类代码示例

本文整理汇总了PHP中Jelly的典型用法代码示例。如果您正苦于以下问题:PHP Jelly类的具体用法?PHP Jelly怎么用?PHP Jelly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Jelly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 /**
  * Uploads a file if we have a valid upload
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @param   bool   $loaded
  * @return  string|NULL
  */
 public function save($model, $value, $loaded)
 {
     $original = $model->get($this->name, FALSE);
     // Upload a file?
     if (is_array($value) and upload::valid($value)) {
         if (FALSE !== ($filename = upload::save($value, NULL, $this->path))) {
             // Chop off the original path
             $value = str_replace($this->path, '', $filename);
             // Ensure we have no leading slash
             if (is_string($value)) {
                 $value = trim($value, '/');
             }
             // Delete the old file if we need to
             if ($this->delete_old_file and $original != $this->default) {
                 $path = $this->path . $original;
                 if (file_exists($path)) {
                     unlink($path);
                 }
             }
         } else {
             $value = $this->default;
         }
     }
     return $value;
 }
开发者ID:rcapp,项目名称:kohana-jelly,代码行数:33,代码来源:file.php

示例2: test_get

 /**
  * Tests for Jelly_Field_BelongsTo::get()
  *
  * @dataProvider  provider_get
  * @param         Jelly         $builder
  * @param         bool          $loaded
  * @return        void
  */
 public function test_get($builder, $loaded)
 {
     $this->assertTrue($builder instanceof Jelly_Builder);
     // Load the model
     $model = $builder->select();
     // Ensure it's loaded if it should be
     $this->assertSame($loaded, $model->loaded());
 }
开发者ID:piotrtheis,项目名称:jelly,代码行数:16,代码来源:BelongsToTest.php

示例3: save

 /**
  * Implementation of Jelly_Field_Behavior_Saveable
  *
  * @param   Jelly  $model
  * @param   mixed  $value
  * @return  void
  */
 public function save($model, $value, $loaded)
 {
     // Empty relations to the default value
     Jelly::update($this->foreign['model'])->where($this->foreign['column'], '=', $model->id())->set(array($this->foreign['column'] => $this->default))->execute();
     // Set the new relations
     if (!empty($value)) {
         // Update the ones in our list
         Jelly::update($this->foreign['model'])->where(':primary_key', '=', $value)->set(array($this->foreign['column'] => $model->id()))->execute();
     }
 }
开发者ID:jerfowler,项目名称:kohana-jelly,代码行数:17,代码来源:hasone.php

示例4: 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();
 }
开发者ID:netbiel,项目名称:core,代码行数:30,代码来源:api.php

示例5: action_delete

 public function action_delete($id)
 {
     $post = Jelly::select('forum_post')->where('id', '=', $id)->load();
     if ($post->loaded()) {
         $this->title = 'Forum - Post - Delete';
     } else {
         Message::set(Message::ERROR, 'Post does not exist');
         $this->request->redirect('forum');
     }
     if ($this->user->id != $post->user->id) {
         Message::set(Message::ERROR, 'You are not the author of this post.');
         $this->request->redirect('forum');
     } else {
         $topic = Jelly::select('forum_topic')->where('id', '=', $post->topic->id)->load();
         if ($topic->posts > 1) {
             $topic->posts = $topic->posts - 1;
             $topic->save();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
         if ($topic->posts == 1) {
             $topic->delete();
             $post->delete();
             Message::set(Message::SUCCESS, 'Post has been deleted.');
             $this->request->redirect('forum');
         }
     }
     $this->template->content = View::factory('forum/post/delete')->set('post', $post);
 }
开发者ID:joffuk,项目名称:modulargaming,代码行数:30,代码来源:post.php

示例6: 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());
 }
开发者ID:joffuk,项目名称:modulargaming,代码行数:34,代码来源:topic.php

示例7: initialize

 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // All fields are aliased to different columns
     $meta->fields(array('id' => Jelly::field('primary', array('column' => 'id-alias')), 'name' => Jelly::field('string', array('column' => 'name-alias')), 'description' => Jelly::field('string', array('column' => 'description-alias')), '_id' => 'id', '_name' => 'name', '_description' => 'description', '_bar' => 'foo'));
 }
开发者ID:piotrtheis,项目名称:jelly,代码行数:7,代码来源:alias.php

示例8: before

 public function before()
 {
     parent::before();
     // Save the old action so it can be brought back on after
     $this->_action = $this->request->action;
     // Set the current action
     $current_action = $this->request->action;
     $id = $this->request->param('id', NULL);
     // Let's guess the action based on the params
     if (!in_array($this->request->action, array('edit', 'add', 'delete')) and (!is_null($id) or !empty($id))) {
         $current_action = 'read';
     }
     if (!method_exists($this, 'action_' . $this->request->action)) {
         $model = Jelly::select(Inflector::singular($this->request->controller));
         foreach ($model->get_state() as $key => $value) {
             $param = $this->request->param($key, NULL);
             if (!is_null($param)) {
                 $model->set_state($key, $param);
             }
         }
         $this->request->response = Kostache::factory($this->request->controller . '/' . $current_action)->set_model($model);
         // Since the magic has been executed, just execute an empty action
         $this->request->action = 'default';
     }
 }
开发者ID:raeldc,项目名称:kojo-plugin,代码行数:25,代码来源:controller.php

示例9: action_update

 public function action_update()
 {
     $this->content->bind('form', $supply);
     $this->content->bind('errors', $errors);
     $id = $this->request->param('id');
     $supply = Jelly::select('supply', $id);
     $supply->set('product', $supply->product);
     // bez tego nie dziala, lol
     if (!$supply->loaded()) {
         $this->request->redirect($this->_base);
     }
     if ($_POST and !$this->session->get($_POST['seed'], FALSE)) {
         if (in_array($supply->status, array('done'))) {
             unset($_POST['status']);
         }
         if (!in_array($supply->status, array('added'))) {
             unset($_POST['quantity'], $_POST['supplier']);
         }
         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();
         }
     }
 }
开发者ID:TdroL,项目名称:hurtex,代码行数:29,代码来源:supplies.php

示例10: initialize

 public static function initialize(Jelly_Meta $meta)
 {
     // Set database to connect to
     $meta->db(Unittest_Jelly_Testcase::$database_connection);
     // Define fields
     $meta->fields(array('id' => Jelly::field('primary'), 'name' => Jelly::field('string')));
 }
开发者ID:piotrtheis,项目名称:jelly,代码行数:7,代码来源:role.php

示例11: set

 public function set($values, $value = NULL)
 {
     // Accept set($_POST, array('author', 'body'));
     // Only $_POST['author'] and $_POST['body'] will be passed
     if (is_array($values) and is_array($value)) {
         $keys = array_flip($value);
         $values = array_intersect_key($values, $keys);
         $value = NULL;
     }
     parent::set($values, $value);
     if (!empty($this->_unmapped)) {
         $related = array();
         foreach ($this->_meta->fields() as $k => $v) {
             if ($v instanceof Jelly_Field_Relationship) {
                 $related[$k] = Jelly::meta($v->foreign['model']);
             }
         }
         if (!empty($related)) {
             foreach ($this->_unmapped as $k => $v) {
                 foreach ($related as $key => $r) {
                     if ($r->fields($k) !== NULL and $r instanceof Model) {
                         $this->{$key}->set($k, $v);
                         continue;
                     }
                 }
             }
         }
     }
     return $this;
 }
开发者ID:TdroL,项目名称:hurtex,代码行数:30,代码来源:model.php

示例12: 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());
 }
开发者ID:joffuk,项目名称:modulargaming,代码行数:60,代码来源:facebook.php

示例13: action_all

 public function action_all(Params $param)
 {
     $this->content->bind('projects', $projects);
     $projects = Jelly::select('project');
     $this->template->title = __('My works');
     $this->template->active = array('portfolio' => ' class="active"');
 }
开发者ID:TdroL,项目名称:piotrszkaluba.pl,代码行数:7,代码来源:category.php

示例14: input

 public function input($prefix = 'jelly/field', $data = array())
 {
     if (!isset($data['options'])) {
         $data['options'] = Jelly::select($this->foreign['model'])->join('products_suppliers', 'LEFT')->on('products_suppliers.supplier_id', '=', $this->foreign['model'] . ':primary_key')->where('products_suppliers.product_id', '=', $this->product->id)->execute()->as_array($this->foreign['model'] . ':primary_key', $this->foreign['model'] . ':name_key');
     }
     return parent::input($prefix, $data);
 }
开发者ID:TdroL,项目名称:hurtex,代码行数:7,代码来源:supplier.php

示例15: 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);
 }
开发者ID:Toby1810,项目名称:jelly-auth-demo,代码行数:33,代码来源:user.php


注:本文中的Jelly类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。