summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/config/mimes.php3
-rw-r--r--system/core/Input.php15
-rw-r--r--system/core/Output.php67
-rw-r--r--system/libraries/Session.php7
-rw-r--r--user_guide/changelog.html2
-rw-r--r--user_guide/database/active_record.html33
-rw-r--r--user_guide/libraries/output.html15
7 files changed, 118 insertions, 24 deletions
diff --git a/application/config/mimes.php b/application/config/mimes.php
index 58eea5f83..8065794ff 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -97,7 +97,8 @@ $mimes = array( 'hqx' => 'application/mac-binhex40',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
- 'eml' => 'message/rfc822'
+ 'eml' => 'message/rfc822',
+ 'json' => array('application/json', 'text/json')
);
diff --git a/system/core/Input.php b/system/core/Input.php
index 25fe102b5..626245390 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -211,11 +211,12 @@ class CI_Input {
* @param bool true makes the cookie secure
* @return void
*/
- function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL)
+ function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
{
if (is_array($name))
{
- foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name', 'secure') as $item)
+ // always leave 'name' in last place, as the loop will break otherwise, due to $$item
+ foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item)
{
if (isset($name[$item]))
{
@@ -236,6 +237,10 @@ class CI_Input {
{
$path = config_item('cookie_path');
}
+ if ($secure == FALSE AND config_item('cookie_secure') != FALSE)
+ {
+ $secure = config_item('cookie_secure');
+ }
if ( ! is_numeric($expire))
{
@@ -246,12 +251,6 @@ class CI_Input {
$expire = ($expire > 0) ? time() + $expire : 0;
}
- // If TRUE/FALSE is not provided, use the config
- if ( ! is_bool($secure))
- {
- $secure = (bool) (config_item('cookie_secure') === TRUE);
- }
-
setcookie($prefix.$name, $value, $expire, $path, $domain, $secure);
}
diff --git a/system/core/Output.php b/system/core/Output.php
index 7fb9f7916..6644b3bff 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -28,19 +28,24 @@
*/
class CI_Output {
- var $final_output;
- var $cache_expiration = 0;
- var $headers = array();
- var $enable_profiler = FALSE;
- var $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
+ protected $final_output;
+ protected $cache_expiration = 0;
+ protected $headers = array();
+ protected $mime_types = array();
+ protected $enable_profiler = FALSE;
+ protected $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
- var $_zlib_oc = FALSE;
- var $_profiler_sections = array();
+ protected $_zlib_oc = FALSE;
+ protected $_profiler_sections = array();
function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
+ // Get mime types for later
+ include APPPATH.'config/mimes'.EXT;
+ $this->mime_types = $mimes;
+
log_message('debug', "Output Class Initialized");
}
@@ -73,6 +78,8 @@ class CI_Output {
function set_output($output)
{
$this->final_output = $output;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -96,6 +103,8 @@ class CI_Output {
{
$this->final_output .= $output;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -125,6 +134,42 @@ class CI_Output {
}
$this->headers[] = array($header, $replace);
+
+ return $this;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set Content Type Header
+ *
+ * @access public
+ * @param string extension of the file we're outputting
+ * @return void
+ */
+ function set_content_type($mime_type)
+ {
+ if (strpos($mime_type, '/') === FALSE)
+ {
+ $extension = ltrim($mime_type, '.');
+
+ // Is this extension supported?
+ if (isset($this->mime_types[$extension]))
+ {
+ $mime_type =& $this->mime_types[$extension];
+
+ if (is_array($mime_type))
+ {
+ $mime_type = current($mime_type);
+ }
+ }
+ }
+
+ $header = 'Content-Type: '.$mime_type;
+
+ $this->headers[] = array($header, TRUE);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -141,6 +186,8 @@ class CI_Output {
function set_status_header($code = 200, $text = '')
{
set_status_header($code, $text);
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -155,6 +202,8 @@ class CI_Output {
function enable_profiler($val = TRUE)
{
$this->enable_profiler = (is_bool($val)) ? $val : TRUE;
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -174,6 +223,8 @@ class CI_Output {
{
$this->_profiler_sections[$section] = ($enable !== FALSE) ? TRUE : FALSE;
}
+
+ return $this;
}
// --------------------------------------------------------------------
@@ -188,6 +239,8 @@ class CI_Output {
function cache($time)
{
$this->cache_expiration = ( ! is_numeric($time)) ? 0 : $time;
+
+ return $this;
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Session.php b/system/libraries/Session.php
index 0b94340d5..182294059 100644
--- a/system/libraries/Session.php
+++ b/system/libraries/Session.php
@@ -37,6 +37,7 @@ class CI_Session {
var $cookie_prefix = '';
var $cookie_path = '';
var $cookie_domain = '';
+ var $cookie_secure = FALSE;
var $sess_time_to_update = 300;
var $encryption_key = '';
var $flashdata_key = 'flash';
@@ -61,7 +62,7 @@ class CI_Session {
// Set all the session preferences, which can either be set
// manually via the $params array above or via the config file
- foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
+ foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
{
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
}
@@ -658,8 +659,6 @@ class CI_Session {
}
$expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
-
- $secure_cookie = (config_item('cookie_secure') === TRUE) ? 1 : 0;
// Set the cookie
setcookie(
@@ -668,7 +667,7 @@ class CI_Session {
$expire,
$this->cookie_path,
$this->cookie_domain,
- $secure_cookie
+ $this->cookie_secure
);
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index d759686e9..815590dc1 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -74,6 +74,8 @@ Hg Tag: n/a</p>
<li class="reactor">Added <kbd>decimal</kbd>, <kbd>less_than</kbd> and <kbd>greater_than</kbd> rules to the <a href="libraries/form_validation.html">Form validation Class</a>.</li>
<li class="reactor"><a href="libraries/input.html">Input Class</a> methods <kbd>post()</kbd> and <kbd>get()</kbd> will now return a full array if the first argument is not provided.</li>
<li class="reactor">Secure cookies can now be made with the <kbd>set_cookie()</kbd> helper and <a href="libraries/input.html">Input Class</a> method.</li>
+ <li class="reactor">Added <kbd>set_content_type()</kbd> to <a href="libraries/output.html">Output Class</a> to set the output <kbd>Content-Type</kbd> HTTP header based on a MIME Type or a config/mimes.php array key.</li>
+ <li class="reactor"><a href="libraries/output.html">Output Class</a> will now support method chaining.</li>
</ul>
</li>
</ul>
diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html
index 30c45fdde..f2f33e212 100644
--- a/user_guide/database/active_record.html
+++ b/user_guide/database/active_record.html
@@ -489,10 +489,10 @@ echo $this-&gt;db-&gt;count_all_results();<br />
<code>
$data = array(<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
+&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
+&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
+&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
+);<br />
<br />
$this->db->insert('mytable', $data);
<br /><br />
@@ -521,6 +521,31 @@ $this->db->insert('mytable', $object);
<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
+<h2>$this->db->insert_batch();</h2>
+<p>Generates an insert string based on the data you supply, and runs the query. You can either pass an
+<strong>array</strong> or an <strong>object</strong> to the function. Here is an example using an array:</p>
+
+<code>
+$data = array(<br/>
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'My title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'My Name' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'My date'<br />
+&nbsp;&nbsp;&nbsp;),<br />
+&nbsp;&nbsp;&nbsp;array(<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'title' => 'Another title' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'Another Name' ,<br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'date' => 'Another date'<br />
+&nbsp;&nbsp;&nbsp;)<br/>
+);<br />
+<br />
+$this->db->insert_batch('mytable', $data);
+<br /><br />
+// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')</code>
+
+<p>The first parameter will contain the table name, the second is an associative array of values.</p>
+
+<p class="important"><strong>Note:</strong> All values are escaped automatically producing safer queries.</p>
diff --git a/user_guide/libraries/output.html b/user_guide/libraries/output.html
index ab8f1d683..25ec521b1 100644
--- a/user_guide/libraries/output.html
+++ b/user_guide/libraries/output.html
@@ -78,6 +78,21 @@ It is possible, however, for you to manually intervene with the output if you ne
For example, if you build a page in one of your controller functions, don't set the output until the end.</p>
+<h2>$this->output->set_content_type();</h2>
+
+<p>Permits you to set the mime-type of your page so you can serve JSON data, JPEG's, XML, etc easily.</p>
+
+<code>$this->output<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;->set_content_type('application/json')<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;->set_output(json_encode(array('foo' => 'bar')));<br/>
+<br/>
+$this->output<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;->set_output(file_get_contents('files/something.jpg'));</code>
+
+<p><strong>Important:</strong> Make sure any non-mime string you pass to this method exists in config/mimes.php or it will have no effect.</p>
+
+
<h2>$this->output->get_output();</h2>
<p>Permits you to manually retrieve any output that has been sent for storage in the output class. Usage example:</p>