CodeIgniter Forums
Storing "views" in php or the database? - 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: Storing "views" in php or the database? (/showthread.php?tid=20190)

Pages: 1 2


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]kalebheitzman[/eluser]
Hey all!

I am working on a CMS and I have a question about using $this->load->view() and write_file();

I am using write_file() to generate my views files from the database and then of course I am loading the view for the front-end. Is it possible to skip the write_file and pass a string into $this->load->view($string, $data) without changing codeigniter core?

Thx!


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]umefarooq[/eluser]
save you content in database and just pass data to you view like this $this->load->view($string, $data) writing file is not good option


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]kalebheitzman[/eluser]
I am looking for a solution that is as flexible as allowing an enduser to edit the file either in the CMS itself or editing the file and ftp'ing it.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]xwero[/eluser]
Adding variables to a view file is based on including the file and as the file gets included it fetches the variables from the memory. It's not possible to add variables to a string you get from the database.

If i were you i would store the view with a unique name and store that name in the database where it's linked to the urls where it needs to be displayed. This requires not changes to the CI core.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]TheFuzzy0ne[/eluser]
You can create your own layer, and build the output as a string, and then you can use $this->output->set_output() to set the output.

EDIT: Just out of interest, why do you need to create a view each time? Why not just stick to having a template and then passing in variables as intended? Instead of being stored in the database, the view can be written straight to disk.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]kalebheitzman[/eluser]
These views would only be created once and then updated via a textarea tag. I guess I should really just reference the view with the database and read_file() and store the code in it's own php file and not the database?


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]Johan André[/eluser]
You don't need to store templates in the database to edit them from a textarea.
You can read files with php and output the data in the textarea.
When you are done editing you could save the textarea to the same file...

That's how I probably would do it.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]TheFuzzy0ne[/eluser]
I might be missing something but it would make more sense to me to actually write it to a file. It's less database work, and since you're editing a view, it makes sense to write it to the disk. To be honest, I'm not entirely sure where the database even ties into this, since you'd be editing existing views.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]garymardell[/eluser]
I believe the problem is that the views may not exist, for example if a user creates a new "page". I'd definitely be interested if you were to write a library that would allow the creation of "view files" and make them editable.


Storing "views" in php or the database? - El Forum - 07-01-2009

[eluser]Johan André[/eluser]
[quote author="garymardell" date="1246487049"]I believe the problem is that the views may not exist, for example if a user creates a new "page". I'd definitely be interested if you were to write a library that would allow the creation of "view files" and make them editable.[/quote]

If the view does not exist create the file, if it exist overwrite the file?