Welcome Guest, Not a member yet? Register   Sign In
Where do you put the content of the site?
#1

[eluser]marlar[/eluser]
Hi,

I hope you will forgive all my questions, but as a new CI developer I have so many :-)

I suddenly realized that something very basic is unclear to me: Where do you put the different content of your sites?

Like the "About..." part, the FAQ, the Welcome texts etc. Do you hardcode it into your views, or do you put it in a database?

My first idea is to hardcode the text parts in a model called Content, just to get started quickly. Later on I can change the model and pour the content into the database instead. Without having to change my views.

This scheme seems quite obvious, but often the best approach is not the obvious so I am interested in hearing your thoughts.

Best regards,
Martin
#2

[eluser]tonanbarbarian[/eluser]
I think I might have just answered something similar to this in another post.

You want to break your site up into parts, call them modules, elements whatever, so that you can have more control over the display rather than having the entire page in a single view file?

If that is the case look at this post I just wrote

http://ellislab.com/forums/viewreply/329953/

Also what I did not mention in that post (and I will not include code for here) is that you can use a similar system called Layouts , usually implemented as a Library (look in the forums and wiki for examples) that allow you to put code around your view.

Basically the process is
Layout
View
Element
Element
Element

I guess the Layout could load more elements as well
The layout just makes it easy to "skin" or "template" your site without having to change every view

Hope this is what you are looking for
#3

[eluser]ejangi[/eluser]
Whether you put the page content in a view or a database is completely up to you. I wouldn't say that CI really has a "best practice" for this as it's an application framework and not necessarily a CMS, so just put your content where it's going to be most appropriate for your application (and the users of the application).

In one of the sites we're building at work we have all our content in views as the people editing them are web-developers and they can find their way around the HTML when they need to change something. However, if I was to build a site for a client or non-tech-head, I would def put the content in a database and give them a nice little WYSIWYG like TinyMCE or something.

Best of luck!
#4

[eluser]marlar[/eluser]
tonanbarbarian:

That is partly what I mean. But mostly I was speculating on where to put the actual content. Having programmed a lot for Joomla, I am used to thinking CMS, and although this project is definately not a CMS, I like the idea of storing the content in a DB.

ucantblamem's answer seems to indicate that I am not alone with that strategy. This project is for myself in the beginning, but if it gets the succes I am hoping for, I will at some point get someone to maintain the content. There will only be a dozen or so pages with textual content, so a CMS would be overkill. But still, I want to make it easy for non-techies to update the site.

(Now I am scratching my head, thinking about how to structure the controllers and views so that I will get some nice. logical URL's ;-) )

Martin
#5

[eluser]ejangi[/eluser]
Well, just to let you know that what we did was use the _remap() function in the controller so that if someone requested a url like:

http://mysite.com/about/the-team

It would look for a file in /application/views/about/the-team.php. That way we could just add views all over the shop and not have to build controllers for each section. ;-)
#6

[eluser]marlar[/eluser]
Nice! What is the code for _remap() ?
#7

[eluser]Phil Sturgeon[/eluser]
Using routes is another method. Have one controller called Page then re-write:

Code:
$route['page/:any'] = 'page/index/$1';

Then you can do as ucantblamem said and make it use the pagename as a view-name or param from the db, either way it doesnt much matter.

Storing your content in the DB may be a good idea, but for general text, button text, navigation, etc its probably a better idea to use the language library.
#8

[eluser]esra[/eluser]
Aside from storing code in a database or hard coding content in views, you can also load content stored in your language files. You can load any number of language files from a controller and embed the language strings or a variable representing a string in your views. For longer content, you can break language strings into paragraphs using <br /> pairs. Language strings can also be formatted using HTML elements or styles.

You can do a lot of other things with language files that might not immediately be immediately apparent like storing the paths to selected files, defining page titles, module names, form-specific language strings for select lists, etc. At the same time, you promote internationalization for your application.
#9

[eluser]Grahack[/eluser]
There was a very nice screencast by Elliot Laughlin about url, routing and content in db, but I can't find it.
AFAIR, it was on filepanda but the server seems to be down...
Any update on this ?

EDIT: I found them.
#10

[eluser]Majd Taby[/eluser]
The way I do it is by setting up a "content" table, which has `name`, and `content` fields. The name is an identifier and the content is the content. I manage it all in my backend from one place. Then in my controllers, I simply do

Code:
$this->load->model("content");
  $data['about_us'] = $this->content->loadData('about');

I find it works very well for me.




Theme © iAndrew 2016 - Forum software by © MyBB