Permalink
Browse files

Better syntax and session support.

  • Loading branch information...
1 parent 99ce273 commit 7aa63b0d85c658465826939da663be401a595ed4 Phil Sturgeon committed Jul 30, 2010
Showing with 53 additions and 27 deletions.
  1. +17 −5 README.textile
  2. +36 −22 libraries/inputs.php
View
@@ -16,18 +16,30 @@ h3. Installation
h3. Usage
- bc.. Server (HTTP_HOST): {mojo:inputs:server name="http_host"}<br/>
+ At the moment it seems you can only use these tags inside of Layouts.
+
+ h4. Mojo Tags
+
+ Server (HTTP_HOST): {mojo:inputs:server name="http_host"}<br/>
Get value ?foo=: {mojo:inputs:get name="foo"}<br/>
- Set cookie: {mojo:inputs:set_cookie name="some_cookie" value="cookie value"}<br/>
+
+ {mojo:inputs:set_cookie name="some_cookie" value="cookie value"}
Cookie value: {mojo:inputs:cookie name="some_cookie"}<br/>
+
+ {mojo:inputs:session name="some_session" value="session value"}
+ Session value: {mojo:inputs:session name="some_session"}<br/>
+
IP Address: {mojo:inputs:ip_address}<br/>
User Agent: {mojo:inputs:user_agent}
- gives...
+ h4. Output
Server (HTTP_HOST): localhost
Get value ?foo=: bar
- Set cookie:
- Cookie value:
+
+ Cookie value: (this is broke atm)
+
+ Session value: session value
+
IP Address: 127.0.0.1
User Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4
View
@@ -26,7 +26,8 @@ class Inputs
*/
function __construct()
{
- $this->input =& load_class('Input');
+ $this->addon =& get_instance();
+ $this->input =& $this->addon->input;
}
// --------------------------------------------------------------------
@@ -51,9 +52,9 @@ function get($template_data = array())
// --------------------------------------------------------------------
/**
- * Get
+ * Post
*
- * Get a $_GET variable.
+ * Get a $_POST variable.
*
* @access public
* @param array
@@ -69,52 +70,65 @@ function post($template_data = array())
// --------------------------------------------------------------------
/**
- * Get
+ * Session
*
- * Get a $_GET variable.
+ * Set or get a variable to the CodeIgniter/Mojo session.
*
* @access public
* @param array
* @return string
*/
- function cookie($template_data = array())
+ function session($template_data = array())
{
$params =& $template_data['parameters'];
+
+ $this->addon->load->library('session');
- return isset($params['name']) ? $this->input->cookie($params['name']) : '';
+ if ( isset($params['name']) AND isset($params['value']))
+ {
+ $this->addon->session->set_userdata($params['name'], $params['value']);
+ }
+
+ else
+ {
+ return isset($params['name']) ? $this->addon->session->userdata($params['name']) : '';
+ }
}
// --------------------------------------------------------------------
/**
- * Get
+ * Set cookie
*
- * Get a $_GET variable.
+ * Set a $_COOKIE variable.
*
* @access public
* @param array
- * @return string
+ * @return void
*/
- function set_cookie($template_data = array())
+ function cookie($template_data = array())
{
$params =& $template_data['parameters'];
- if ( ! isset($params['name']) OR ! isset($params['value']))
+ if ( isset($params['name']) AND isset($params['value']))
{
- return;
- }
+ $expire = isset($params['expire']) ? $params['expire'] : '';
- $expire = isset($params['expire']) ? $params['expire'] : '';
+ $this->input->set_cookie($params['name'], $params['value'], $expire);
+ }
- $this->input->set_cookie($params['name'], $params['value'], $expire);
+ else
+ {
+ return isset($params['name']) ? $this->input->cookie($params['name']) : '';
+ }
}
// --------------------------------------------------------------------
/**
- * Get
+ * Server
*
- * Get a $_GET variable.
+ * Get a $_SERVER variable.
*
* @access public
* @param array
@@ -130,9 +144,9 @@ function server($template_data = array())
// --------------------------------------------------------------------
/**
- * Get
+ * IP Address
*
- * Get a $_GET variable.
+ * Get the users IP Address
*
* @access public
* @param array
@@ -146,9 +160,9 @@ function ip_address()
// --------------------------------------------------------------------
/**
- * Get
+ * User Agent
*
- * Get a $_GET variable.
+ * Get the users user agent.
*
* @access public
* @param array

0 comments on commit 7aa63b0

Please sign in to comment.