-
mtylerb Newbie

-
Posts: 5
Threads: 1
Joined: Apr 2015
Reputation:
0
04-05-2015, 02:13 PM
(This post was last modified: 04-05-2015, 03:57 PM by mtylerb.)
I'm struggling a little here and could use some help. I want to be able to have my views/templates be database based. This way I can have my views editable in an admin section. Unfortunately, the view() command requires a php file and I'm kind of new to CodeIgniter. I'm using CodeIgniter 3. Anybody have any suggestions? I thought about having the view call another view, but that doesn't follow best practices (at least in my head).
Thanks in advance,
Tyler
-
gadelat Member
  
-
Posts: 128
Threads: 3
Joined: Feb 2015
Reputation:
7
Pass the HTML code saved in database to view as data. Quick example:
Controller:
PHP Code: function index() { $this->load->model('views'); $view_data = array( 'navigation' => $this->views->get_navigation(), 'content' => $this->views->get_content(), ); $this->load->view('main_view', $view_data); }
Your main view:
PHP Code: <?=$navigation?> <hr> <?=$content?>
-
mtylerb Newbie

-
Posts: 5
Threads: 1
Joined: Apr 2015
Reputation:
0
(04-05-2015, 03:35 PM)gadelat Wrote: Pass the HTML code saved in database to view as data. Quick example:
Controller:
PHP Code: function index() { $this->load->model('views'); $view_data = array( 'navigation' => $this->views->get_navigation(), 'content' => $this->views->get_content(), ); $this->load->view('main_view', $view_data); }
Your main view:
PHP Code: <?=$navigation?> <hr> <?=$content?>
Hey gadelat,
Thanks for the quick reply. The issue being that I also want to be able to put limited PHP, such as variables and the sort into the database to have them eval'd just like the $this->load->view('file.php', $data); would do. I am currently doing exactly what you stated, but this requires that the database be static and that's not going to do what I want.
Thanks,
Tyler
-
gadelat Member
  
-
Posts: 128
Threads: 3
Joined: Feb 2015
Reputation:
7
04-05-2015, 11:58 PM
(This post was last modified: 04-06-2015, 12:01 AM by gadelat.)
-
mtylerb Newbie

-
Posts: 5
Threads: 1
Joined: Apr 2015
Reputation:
0
(04-05-2015, 11:58 PM)gadelat Wrote: Use parser library
As far as I can tell, that is for parsing pseudo-php. {$title} and the sort. I want it to parse full php. Maybe I misunderstood the documentation?
Tyler
-
mtylerb Newbie

-
Posts: 5
Threads: 1
Joined: Apr 2015
Reputation:
0
(04-06-2015, 11:13 PM)gadelat Wrote: Yes, that should be enough for your needs, you shouldn't have complex logic in your views. Evaluating code from database is bad idea, but if you really want to do this, use eval()
Unfortunately, eval() would require that I find each and every PHP statement manually within the view. I just figured CI had this ability built in seeing as the load->view() does it. I don't want to have to use {} to make pseudo PHP. I'm not talking about complex statements, I'm very aware that complex statements should be kept out of the view and that's what I intend on keeping to. I'm talking about using real PHP to make some simple loop or conditional and/or echo statements. For my purposes, it's easier to read and understand than seeing a bunch of curly braces. Since I'm the only one who's going to be programming and designing these views, I really don't care if it's easier for non-programmers to learn the pseudo PHP.
I also don't want to use file based views, I'd prefer to use database based views. I'd just like to be able to pull my view from the database (which already works fine) then have CI evaluate the pulled view and display the page.
-
gadelat Member
  
-
Posts: 128
Threads: 3
Joined: Feb 2015
Reputation:
7
(04-07-2015, 05:47 PM)mtylerb Wrote: Unfortunately, eval() would require that I find each and every PHP statement manually within the view. Nope.
PHP Code: eval(' echo "wut";?> badamtss <?php foreach(["lal1", "lal2"] as $i) { echo $i; }');
|