Welcome Guest, Not a member yet? Register   Sign In
Add a single database entry?
#1

[eluser]Friedebarth[/eluser]
Hello CodeIgniters. I've watched the video tutorials and have read the userguide, but I can't figure out how to do the following.

My goal is to develop a CMS for simming fleets/clans specialised in Star Trek fandom. Therefore, I need the guys being able to easily edit the data (fleet name etc.), so I thought I could pull it from the database, where they could edit it (yes, I am going to add a form :lolSmile, and that's why I created a table called fms_start (like my index controller and it's viewfile.

This table has: id (quite unnecessary because there should only be one entry), which is auto_increment and int. Then, it has fname, body and footer. Now, the defaults for these are iFleet, Your text here and Copyright Joe Bloggs. Now what I wanted to do is this (database data in [] brackets):

Code:
<html>
<header>
<title>[fname]</title>
</header>
<body>
<h1>[fname]</h1>
[body]
<br>
<br>
<small>[footer]</small>
&lt;/body&gt;
&lt;/html&gt;

Now I didn't really get how to do that. Could someone please help me out? Thanks Smile

Your Friedebarth
#2

[eluser]jalalski[/eluser]
You'll need to:
1. create a Model to handle the database connectivity
2. create a Controller to load the model, get the record with that id. This controller is where you can load the Form_validation helper and provide defaults if needed.
3. create a view (based on what you have above) which will display the record.

Your model will handle loading records, creating new ones and saving records.

HTH
#3

[eluser]Friedebarth[/eluser]
[quote author="jalalski" date="1231271362"]You'll need to:
1. create a Model to handle the database connectivity
2. create a Controller to load the model, get the record with that id. This controller is where you can load the Form_validation helper and provide defaults if needed.
3. create a view (based on what you have above) which will display the record.

Your model will handle loading records, creating new ones and saving records.

HTH[/quote]

Well, I've got a controller which loads the database and a view that loads the controller, but somehow I don't unterstand the models (maybe cause there's no tutorial on them). Is there an example on them somewhere?
#4

[eluser]jalalski[/eluser]
[quote author="Friedebarth" date="1231273049"]Well, I've got a controller which loads the database and a view that loads the controller, but somehow I don't unterstand the models (maybe cause there's no tutorial on them). Is there an example on them somewhere?[/quote]

Well, there are a few posts here on the forum about setting up and using the MVC framework (which is what CodeIgniter uses). But basically the URL that appears in your browser location bar will call a controller class. This class typically loads the model(s) that are needed, sets up the data and then calls the view, which displays the data.

You say you've looked at the video tutorials, but it may be worth viewing it again, particularly the one "Creating a Blog in 20 minutes" from Derek Jones, which covers all the basics that you need.
#5

[eluser]Friedebarth[/eluser]
Couldn't I do something like:

Code:
&lt;?php IF $this->db->get('fms_start', 'id')==1 {
$fname=$this->db->get('fms_start', 'fname')
$body=$this->db->get('fms_start', 'body')
$footer=$this->db->get('fms_start', 'fname')
} ?&gt;
&lt;html&gt;
&lt;header&gt;
&lt;title&gt;&lt;?php echo=$fname ?&gt;&lt;/title&gt;
&lt;/header&gt;
&lt;body&gt;
<h1>&lt;?php echo=$fname ?&gt;</h1>
&lt;?php echo=$body ?&gt;
<br>
<br>
<small>&lt;?php echo=$footer ?&gt;</small>
&lt;/body&gt;
&lt;/html&gt;
#6

[eluser]jalalski[/eluser]
You could. But why?

You risk throwing away the whole power of using an MVC framework and may as well go back to writing straight PHP code.




Theme © iAndrew 2016 - Forum software by © MyBB