11-29-2010, 10:48 AM
[eluser]Leovenous[/eluser]
Hello. I'm running a new CI install, so latest version.
Be forewarned, I have a lot to learn but I really want to "get it". I have some experience in MCV... its just programming, syntax and OOP that gets me.
What I want to accomplish is have my simple 3-field form take information, flash a confirmation, and add their name as the last-submitter.
Something is awry.
My model (don't laugh) is stealer.php
In the above I realized that I don't need the 'cache' table at all. I could snatch the name of the most recent signer from the signer list (duh moment). That's easy enough to change in the model, but I'm not sure how that would play out in the controller.
My controller is prerelease.php. Note that "pre" is for the view: pre.php. I'll include only the pertinent functions:
In the view, pre.php, before the form I have this:
Then after the form, where I have my mention of the last signer:
I don't like running a foreach when I know there is only one bit of data, but I don't know how to pass a query as a single variable rather than an array. So from the model onward I treat the results like an array, even though I'm only after one column in one row.
The companion question is why isn't the flash message displaying? (I am autoloading session) Feel free to put bogus entries in the form today (November 29th). I'll clear out that data tomorrow.
I'd really like to get a grip on this. I'm impressed with CI so far.
Hello. I'm running a new CI install, so latest version.
Be forewarned, I have a lot to learn but I really want to "get it". I have some experience in MCV... its just programming, syntax and OOP that gets me.
What I want to accomplish is have my simple 3-field form take information, flash a confirmation, and add their name as the last-submitter.
Something is awry.
My model (don't laugh) is stealer.php
Code:
<?php
class Stealer extends model {
function addInterest($data) {
$this->db->insert('interest', $data);
return;
}
function addCache($jett) {
$this->db->insert('cache', $jett);
return;
}
function getLastSignup() {
$this->db->get('cache');
$this->db->order_by('id', 'desc');
$this->db->limit(1);
$q = $this->db->get('cache');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
In the above I realized that I don't need the 'cache' table at all. I could snatch the name of the most recent signer from the signer list (duh moment). That's easy enough to change in the model, but I'm not sure how that would play out in the controller.
My controller is prerelease.php. Note that "pre" is for the view: pre.php. I'll include only the pertinent functions:
Code:
function index()
{
$data['row'] = $this->stealer->getLastSignup();
//echo $data;
//die();
$this->load->view('pre', $data);
}
public function submit() {
if ($this->_submit_validate() === FALSE) {
$this->index();
return;
}
$data = array(
'fname' => $this->input->post('fname'),
'email' => $this->input->post('email'),
'zipc' => $this->input->post('zipc')
);
$name = $this->input->post('fname');
$jett = array('latestu' => $name);
$this->stealer->addInterest($data);
$this->stealer->addCache($jett);
$this->session->set_flashdata('notice', 'Your request was processed. Thanks for joining the movement!');
$this->load->view('pre');
}
In the view, pre.php, before the form I have this:
Code:
<p><?php echo $this->session->flashdata('notice'); ?></p>
Then after the form, where I have my mention of the last signer:
Code:
<p style="padding-top:12px;">A cheer goes up for our latest signer, <?php foreach ($row as $r) { echo $r->latestu; } ?>!</p>
I don't like running a foreach when I know there is only one bit of data, but I don't know how to pass a query as a single variable rather than an array. So from the model onward I treat the results like an array, even though I'm only after one column in one row.
The companion question is why isn't the flash message displaying? (I am autoloading session) Feel free to put bogus entries in the form today (November 29th). I'll clear out that data tomorrow.
I'd really like to get a grip on this. I'm impressed with CI so far.