CodeIgniter Forums
Why does this code break my view? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why does this code break my view? (/showthread.php?tid=2154)



Why does this code break my view? - El Forum - 07-18-2007

[eluser]Chad Crowell[/eluser]
With this in my controller, the form view displays fine:

Code:
<?php
class Sell extends Controller {

function index()
{

  $data['title']    = "RunwayJunkie.com - Buy & Sell Designer Clothing";

  $data['templates']   = array("front/templates/header", "front/partials/item_addform", "front/templates/footer");
  
  $this->load->view('front/loader', $data);
}
  
}
?>

However, the second function, to collect the form data, keeps the form view from showing up. I can't figure out whats wrong.

Code:
<?php
class Sell extends Controller {

function index()
{

  $data['title']    = "RunwayJunkie.com - Buy & Sell Designer Clothing";

  $data['templates']   = array("front/templates/header", "front/partials/item_addform", "front/templates/footer");
  
  $this->load->view('front/loader', $data);
}



function insert_item()
{

  $data = array(
   'seller_id'   = '1';
   'category_id'   = $this->input->post('category_id', TRUE);
   'brand_id'   = $this->input->post('brand_id', TRUE);
   'size_id'   = $this->input->post('size_id', TRUE);
   'item_title'  = $this->input->post('item_title', TRUE);
   'item_desc_short' = $this->input->post('item_desc_short', TRUE);
   'item_desc_long' = $this->input->post('item_desc_long', TRUE);
   'price'    = $this->input->post('price', TRUE);
   'condition_id'  = $this->input->post('condition_id', TRUE);
   'color'    = $this->input->post('color', TRUE);
   'material'   = $this->input->post('material', TRUE);
   'measurements'  = $this->input->post('measurements', TRUE);
   'img_1'    = '1';
   'img_2'    = '2';
   'img_3'    = '3';
   'img_4'    = '4';
  );
  
  $this->db->insert('items', $data);
  
}

}
?>


This sort of thing is so frustrating- in the time its taken me to build 3 pages in CI, I could have built this client's entire app in dreamweaver...


Why does this code break my view? - El Forum - 07-18-2007

[eluser]座頭市[/eluser]
Your syntax for the array is wrong:

Code:
/*
|=============
| Notice that you should be using =>
| not = to set key/value pairs.
| Also, you should be using commas not
| semi-colons to separate the data.
|=============
*/
  $data = array(
   'seller_id'   => '1',
   'category_id'   => $this->input->post('category_id', TRUE),
   'brand_id'   => $this->input->post('brand_id', TRUE),
   'size_id'   => $this->input->post('size_id', TRUE),
   'item_title'  => $this->input->post('item_title', TRUE),
   'item_desc_short' => $this->input->post('item_desc_short', TRUE),
   'item_desc_long' => $this->input->post('item_desc_long', TRUE),
   'price' => $this->input->post('price', TRUE),
   'condition_id'  => $this->input->post('condition_id', TRUE),
   'color' => $this->input->post('color', TRUE),
   'material'   => $this->input->post('material', TRUE),
   'measurements'  => $this->input->post('measurements', TRUE),
   'img_1' => '1',
   'img_2' => '2',
   'img_3' => '3',
   'img_4' => '4'
  );



Why does this code break my view? - El Forum - 07-18-2007

[eluser]batteries[/eluser]
1. dreamweaver is garbage.
2. your syntax is all bat-shit wrong. you can't have semi-colons separating array key/value pairs. you need to use commas. and if you want to assign values to a key you use => not =

this syntax:
Code:
$hey = array('key' => $value, 'key2' => $value2);



Why does this code break my view? - El Forum - 07-18-2007

[eluser]Chad Crowell[/eluser]
OK got it guys- thanks so much. And while DW may be a tool of the past, I was making a point that all this "CI is so easy" stuff is not so true- when you figure it out its great, but figuring it out is very time consuming.


Why does this code break my view? - El Forum - 07-18-2007

[eluser]batteries[/eluser]
[quote author="Chad Crowell" date="1184838649"]..but figuring it out is very time consuming.[/quote]

..but the best part! Smile


Why does this code break my view? - El Forum - 07-18-2007

[eluser]座頭市[/eluser]
[quote author="Chad Crowell" date="1184838649"]I was making a point that all this "CI is so easy" stuff is not so true- when you figure it out its great, but figuring it out is very time consuming.[/quote]
CI is remarkably easy compared to other PHP frameworks I've tried, but that does not circumvent the need to learn about the underlying language (like basic syntax) before charging headlong into Framework Land, whether it be PHP, Ruby, Python etc.


Why does this code break my view? - El Forum - 07-18-2007

[eluser]Chad Crowell[/eluser]
I'm very good with PHP...its MVC I'm all twisted up with


Why does this code break my view? - El Forum - 07-19-2007

[eluser]Phil Sturgeon[/eluser]
[quote author="Chad Crowell" date="1184840005"]I'm very good with PHP...its MVC I'm all twisted up with[/quote]

And basic PHP Syntax? Tongue


Why does this code break my view? - El Forum - 07-19-2007

[eluser]Chad Crowell[/eluser]
punk


Why does this code break my view? - El Forum - 07-19-2007

[eluser]Phil Sturgeon[/eluser]
whats wrong with being a punk?! :coolmad: