Welcome Guest, Not a member yet? Register   Sign In
Storing "views" in php or the database?
#1

[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!
#2

[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
#3

[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.
#4

[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.
#5

[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.
#6

[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?
#7

[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.
#8

[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.
#9

[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.
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB