TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-11-2009, 09:25 PM   #1 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default Edit post with CodeIgniter

I'm playing with CodeIgniter for the first time and I've managed to confuse myself. I've made a very simple blog script which I can add posts with, now I want to make an edit post page.

My controller looks like:
PHP Code:
    function edit_posts()
    {
        
$this->load->helper('form');
        
$this->load->model('posts_table');
        
$data['posts'] = $this->posts_table->edit_post();
        
$this->load->view('edit_posts'$data);
    } 
And the model:
PHP Code:
    function edit_post() 
    {
        
$this->db->where('id'$this->uri->segment(3));
        
$query $this->db->get('posts');
    } 
How do I display the stuff it gets from the database in my view? All the examples I can find use loops but I'm only displaying one result so I don't need a loop do I?
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 11-24-2009, 02:22 AM   #2 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

I'm not very familiar with Code Igniter, but if it's just one result I wouldn't think you would need a loop. Atleast, I have never seen a loop used to print just one single result. I am not too familiar with CI's database abstraction, but check out the manual and see about pulling just one row set. If anything you might have to loop through an array of one rows data, but that depends on how CI returns its row set.
Killswitch is offline  
Reply With Quote
Old 11-24-2009, 02:30 AM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

If you're practicing by writing a blog script, there's no reason not to use a loop either. Always design with the other side of the tunnel in sight - who would want a blog that only ever displayed a single post? Loops can be used to display a single item, or multiple items, the beauty of them is that they don't need to know beforehand, they'll just do their job.

As for a useful answer to your question, I have none. Never used CodeIgniter. The name freaks me out, cause the last thing I need is for my computer to spontaneously combust.
delayedinsanity is offline  
Reply With Quote
Old 11-24-2009, 12:12 PM   #4 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

The second argument of $this->load->view(); takes the array with values. The arraykeys (names) of easy value in the array is transformed into a variable in the view itself. (extract() function)

So when I call the view like this from my controller:

$this->load->view('test', array('test' => 'hello world'));

I can read it like this in my view:

My testvalue: <?=$test?>
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 11-24-2009, 09:22 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
<?=$test?>
*smacks your hand*
delayedinsanity is offline  
Reply With Quote
Old 11-28-2009, 12:53 PM   #6 (permalink)
The Contributor
 
Izym's Avatar
 
Join Date: Sep 2007
Posts: 32
Thanks: 0
Izym is on a distinguished road
Default

Another thing would be for you to name your methods a bit different. Both of the mentioned methods should simply be named edit(), seeing as the class name says - or should at least - either Post (model) or Posts (controller) (or something similar to that).
Izym is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
My post shows up as NEW allworknoplay Feedback 5 05-06-2009 01:35 PM
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 06:36 AM
Edit php.ini within PHP ETbyrne General 5 08-16-2008 12:35 PM
Edit Bug Haris Feedback 3 11-29-2007 01:19 AM


All times are GMT. The time now is 02:12 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design