| CARVIEW |
I am trying to pass an array of POST data from a controller into a model.
How is this done? How can I then access the data in the model?
The controller code look like this (is it correct?):
$result = $this->items_model->add( array(
'ite_owner' => $this->post('user'),
'ite_type' => $this->post('type'),
'ite_value_1' => $this->post('value_1'),
'ite_value_2' => $this->post('value_2'),
'ite_value_3' => $this->post('value_3'),
'ite_value_4' => $this->post('value_4'),
'ite_value_5' => $this->post('value_5'),
'ite_access' => $this->post('access')
));
Please help!
]]>Model methods from MY_Model:
protected function convert_date_to_sqldate($date)
{
return date('Y-m-d hh:mm:ss', strtotime($date));
}
public function add($insert_information = array(), $explict_types = array())
{
if(count($insert_information) == 0)
{
return FALSE;
}
foreach($insert_information as $key => &$value)
{
if(isset($explict_types[$key]))
{
switch($explict_types[$key])
{
case 'date':
$insert_information[$key] = $this->convert_date_to_sqldate($value);
break;
}
}
}
$this->db->insert($this->primary_table['name'], $insert_information);
if($this->db->affected_rows() > 0)
{
return $this->read($this->db->insert_id());
}
else
{
return FALSE;
}
}
Code on page:
$insert_data = array(
'date' => $this->input->post('date'),
'amount' => $this->input->post('amount'),
'account_number' => $this->input->post('account_number'),
'type' => $this->input->post('transaction_type')
);
$explicit_types = array('date' => 'date');
if($query = $this->Transaction->add($insert_data, $explicit_types))
{
redirect('transactions/browse');
}
else
{
echo 'Insert failed';
}
SELECT * FROM albums
WHERE artist_name = 'Bedrock'
AND album_name = 'Emerald (including Charlie May remix)'
which works within the mysql console.
I am using ActiveRecord within C.I.:
$q = $this->db->get_where('albums',array('artist_name'=>$artist, 'album_name'=>$album));
However the parentheses are automatically escaped before querying the database:
SELECT *
FROM (`albums`)
WHERE `artist_name` = 'Bedrock'
AND `album_name` = 'Emerald & # 4 0 ;including Charlie May remix& # 4 1 ;'
(EDIT: I have added spaces within the escaped characters, the forum converted them to their ASCII form)
....and nothing is returned
I have tried the C.I. wiki work around but still no success.
How can I query the database with field values that contain parenthesis?
Kind regards,
Stegre.
The driver is missing the _truncate() function and the $_count_string variable, which are required for some SQL operations. The following changes must be made to pdo_driver.php:
After line 47, add the following:
var $_count_string = "SELECT COUNT(*) AS ";
Around line 530, change the _delete() function so it reads as follows:
function _delete($table, $where=null)
{
$sql = "DELETE FROM ".$this->escape_table($table);
if (!empty($where)) {
$sql .= " WHERE ".implode(" ", $where);
}
return $sql;
Then add the following lines:
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
* @access public
* @param string the table name
* @return string
*/
function _truncate($table, $where=null)
{
return $this->_delete($table, $where);
}
But i’m not sure about my validation:
$this->form_validation->set_rules(
array(
array(
"field" => "title",
"label" => "Title",
"rules" => "required|xss_clean"
),
array(
"field" => "body",
"label" => "News body",
"rules" => "required|xss_clean"
),
array(
"field" => "body_extra",
"label" => "Body extra",
"rules" => "xss_clean"
),
array(
"field" => "author_login",
"label" => "Authors login",
"rules" => "required|xss_clean"
)
)
);
$_POST['id'] = 0;
$_POST['author_id'] = 0; //disable this in future
$_POST['mtime'] = date("Y-m-d H:i:s", 3601 );
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
if (!$this->form_validation->run()) {
$this->data['title'] = "News: Add (errors)";
$this->load->view('news_add', $this->data);
}
else {
$this->data['title'] = "News: new post inserted";
$this->load->view('news_inserted', $this->data);
$this->db->insert('news', $_POST);
}
Web form, from which i sent data:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"https://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?=$title?></title>
</head>
<body>
<?=validation_errors()?>
<?php
echo "<p>",
form_open('news/insert', array('class' => 'email', 'id' => 'myform')), "</p>",
"<p>", form_input(array(
"name" => "title",
"value" => set_value("title", "Title")
)), "</p>",
"<p>",form_textarea(array(
"name" => "body",
"value" => set_value("body","News Body")
)), "</p>",
"<p>",form_textarea(array(
"name" => "body_extra",
"value" => set_value("body_extra","Extra body")
)), "</p>",
"<p>", form_input(array(
"name" => "author_login",
"value" => set_value("author_login","Author")
)), "</p>",
"<p>",form_submit(array(
"value"=>"Submit"
)), "</p>",
form_close();
?>
</body>
</html>
Table description in database:
CREATE TABLE `cms`.`news` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` tinytext NOT NULL,
`body` text NOT NULL,
`body_extra` text NOT NULL,
`ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'creation time',
`mtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'modification time',
`author_id` int(11) NOT NULL,
`author_login` tinytext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=64 DEFAULT CHARSET=latin1
————————
Do i forgot something to check?
i’m using image manipulation class, i’m using ‘dynamic_output’ and it’s necessary for my application. but i have a problem i want to resize an image and watermark it without saving it, i want only to resize and watermark the source image without affecting the source image. and i can’t save a temporary image. for example i can’t resize the image save it and watermark it again.
Thanks
]]>In other words, is there any information about current state of 2.0 version(which is currently in development), how much is CI 2 in development?
I want to start a new project with CI, but I’m worrying about current CI 2 dev-version security…
]]>Example :-
$this->load->library('image_moo');
// single thumbnail
$this->image_moo
->load("myfile.x")
->resize(200,200)
->save("thumb.x");
if ($this->image_moo->error) print $this->image_moo->display_errors();
// thumbnail and large, large watermarked
$this->image_moo
->load("myfile.x")
->resize(240,200)
->save("thumb.x")
->resize(1024,768)
->save("medium.x")
->resize(1600,1024)
->save("large.x");
if ($this->image_moo->error) print $this->image_moo->display_errors();
// add watermarks
$this->image_moo
->load("myfile.x")
->load_watermark("image.x")
->resize(240,200)
->save("thumb.x")
->resize(1024,768)
->watermark(2)
->save("medium.x")
->resize(1600,1024)
->watermark(8)
->save("large.x");
if ($this->image_moo->error) print $this->image_moo->display_errors();
// create watermark text
$this->image_moo
->load("myfile.x")
->make_watermark_text("copyright me","font.ttf")
->resize(1024,768)
->watermark(2)
->save("medium.x");
if ($this->image_moo->error) print $this->image_moo->display_errors();
Those are a couple of basic uses but it has a couple of extras for resize ![]()
resize($max_width,$max_height,$pad=FALSE)
So resize will work as normal, e.g. an image of 1000 x 600. resize(200,200) your output image would be 200 x 120. Sometimes you want this as a square image, so set pad and the returned image will be 200 x 200 and the image centralised on to it. The background colour can be set with $this->image_moo->set_background_colour($html_colour=”#ffffff”) (default is white #ffffff.
There is also another resize, resize_crop($x,$y) which is similar to resize but truncates the original image to get the largest part in the resize. e.g. a 1000 x 600 image resize_crop(200,200) returns a 200 x 200 image, but the source will be the centralised 600 x 600 part of the main image (does that sound right?!)
There are no docs at the moment as this is just version 0.7.2 while I continue the project I need this for, but all feedback is welcome.
]]>i’m using codeigniter to build a project and right now i need to create a thumb depending on user choice. like he will give me X1,Y1,X2,Y2,X3,Y3,X4,Y4 i want to crop the image depending on that 4 points. i checked the image manipulation class. the crop function seems to be very strange. any help please ?
something like this
P1 = (100,100)
P2 = (100,200)
P3 = (200,100)
P4 = (200,200)
First of all thanks a bunch for the great help so far - I am currently into my first steps on developing a website with CodeIgniter, and I absolutely love the framework.
I have noticed that, in a lot of cases, when I submit a form on a view I would just like to go back to the original page where the user filled out the form. This goes for a lot of things on the website I am creating, for example, the website includes a shopping cart - every time the cart is updated (I am using the Cart class…) I would just like to send the user back to where he came from.
Is there an easy way to do this? Can I tell a controller: “handle a user form, but when loading the view just go back to the original page”.
This also goes for example for clicking a link that adds a product to a cart, deleting an item from a cart , ...
Thanks in advance
]]>