Welcome Guest, Not a member yet? Register   Sign In
Templating a more generic way
#1

Hi Guys,

I'm just in the throws of finishing of ignitedcms for developers and what works great is managing front end content from the backend and using a template language to easily render the view.

This is great, but what happens when you want the front end to do something more, such as get post information from a form and save it to a database, such as a shopping cart example.

For this I can't see a way other than breaking codeigniter and writing your own controller to accept data and save it somewhere.

The only way around this is to extend the templating engine, so much so, it's almost like wrapping codeigniter functions in twig shorthand which to me sounds backward.

Just wondering what everyone else thinks of this. It sounds like a bad idea. Maybe there isn't a way to generalise it.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#2

Anyone have any advice? Would love to hear.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

The controller that is generating the form can check if a form has been posted. 

PHP Code:
if($post $this->input->post()) {
 
   // Process your $post data here
} else {
 
   // Show the view with the form

Reply
#4

Bonfire's template library uses an idea called "blocks" which I think is similar to what you're trying to conceptualize:
In the "parent" view, you can add some code which indicates the anchor point for a "block" with a name supplied in the code:

PHP Code:
Template::block('theNameOfTheBlock''optional/default/view/for/this/block'); 

Obviously, if you were using a templating language, you would want to define this using some syntax that was relevant to that templating language. The point is that you would have some indication that you were defining a block, a name for the block, and, optionally, a default view to be loaded into that block.

In your controller, you can change the view displayed in any block using the name of the block:

PHP Code:
Template::set_block('theNameOfTheBlock''some/other/view'); 

You would probably want to also pass data to the view when setting the block (Bonfire's library allows you to pass data in Template::block() rather than Template:Confusedet_block(), but that doesn't really make sense with what you're trying to do, in my opinion).

As Martin7483 stated, you can check whether a form has been posted, and you can take that a step further by including data in the form (in hidden inputs, for instance) which indicates how the form should be handled. You would need to take a lot of extra steps (and be especially paranoid) to handle it in a secure fashion, but it should be possible.
Reply
#5

Yeah, I thought about it some more and I don't think it is worth wrapping the standard codeigniter php functions to query and insert into a database around another templating language. But I had to ask the question.

Thanks for the replies.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#6

Hi guys,

I am just about to revisit this... So I'm going to explore the idea of creating blocks and allowing the user to create their tables within the CMS. I'll let you know how I get on and if I have any other questions.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB