I've been asked to create a CakePHP plugin that would allow users to dynamically generate forms. This doesn't sound too hard in and of itself (pull fields from DB, figure out what kind of input, show in HTML), but I don't understand how I can "save" the forms to a new page.
From my understanding, Wordpress circumvents this problem by storing all data in the database, and can use shortcodes to just "insert" the form into another page. Seeing that CakePHP handles relies on CTP files to define views (and not Database fields), I don't see any simple approach to doing this.
Is this goal of a WYSIWYG form editor possible in CakePHP (without having to resort to terrible practices like editing CTP/PHP files from within the app)? If so, can you point me towards some strategies I can use to develop this plugin?
I'm not sure what you do with the dynamic form, to me it sounds like you're describing two totally different things.
Save the structure of the generated form somehow in the DB, key/value, serialized via php or as json object
Return the data, set it to the view
Write a helper that turns the structure that describes the form again in
The editable version, restore the form
Parses the structure and returns the HTML of whatever the fields of the form should do
You'll have to write your own parser that looks for things like [gallery id=1] and replace that with the result of a function call. Assuming that this is what you want to do. So you'll have to map the "gallery" to a functional call. I think the best here would be to use requestAction()
The *.ctp files are what WP considers it's template files, and honestly, Wordpress is just a horrible awkward piece of software from a developer perspective.
Related
Is it possible to generate nice dynamic/permalink URLs based on $_POST submission form data?
Essentially I'd like the page.php I direct a form to - to create it's own URL from data that's in the $_POST array.
I've only seen methods to create dynamic/permalink URLs from within frameworks or based on SQL database rows/columns.
Whereas, I'd like to go from mywebsite.com/index.php to mywebsite.com/[topic-keyword-from-form-submission]/
A more direct or likely example would be:
mywebsite.com/european-union/
On the index.php page are various category style keywords as buttons within forms - no open text input boxes.
Are there any security concerns/considerations if the above is achievable ?
I would suggest that you start to use mvc. Most framework now are also using MVC. I would also suggest to start using a framework as else you will have to build a routing system each time which takes up time you could have used somewhere else.
I would suggest laravel :)
In shorts it's possible but not worth the time.
I'm creating my own CMS from scratch as a way to build my php and mysql skills. Everything is going well, but I'm at the point where I want to create individual post pages for each blog post I write. So the index.php page has a list of all my blogs with snippets of each post and there is a read more button that should take the user to the full page for each blog post. Each post has a url created from the blog title entered in the "create post" form. I'm trying to figure out how to create unique pages for each post without passing the title, subhead, post content and other info through the GET.
This also dovetails with another feature I'm trying to add. I want to be able to create individual pages using a "create page" form like I did for my posts. So if I want an "about us" page I go to my admin form, fill out the title, add the content, and when I hit submit it creates the page dynamically. I have thought all day about how I'd do these two things but can't quite figure out how I can do this.
FYI, I'm not asking for code, I just need a push in the right direction as I try to conceptualize how to achieve this. Thanks!
If you're not familiar with the Model-View-Controller pattern, reading up on it might be prudent. MVC is frequently the right starting place for high-level design of web applications.
Also, a CMS is a big enough project you should consider using a PHP framework like CodeIgniter, Symfony, Zend, etc. to make your life easier. It removes a lot of the drudge work and common tasks.
Dynamic Page Creation and Display
I think you want to split it into two things: the text content (basically what you put in the forms) and the HTML templating surrounding that content.
When you make a page or blog post, you would want to store the actual content (what you type into the creation form) in a database of some sort (not necessarily an RDBMS, but if you're trying to build MySQL skills it's a reasonable choice).
Then you would use a separate function to bind that content into an HTML template and present it to the user when they load a given page.
URL Routing
To get nicer-looking URLs you can use something like apache's mod_rewrite. You can use that to convert a URL like this:
posts/how-to-make-a-cms
to this:
posts.php?title=how-to-make-a-cms
Then you can have posts.php read from GET as normal. How you choose to do the conversion is pretty open-ended.
To avoid getting really complicated rewrites, people often just structure everything to go to a central routing script which figures out what class and method to call and what arguments to pass it. So it would rewrite the URL above to:
main.php?a=posts/how-to-make-a-cms
Then main.php would parse out the segments of that argument from GET and figure out where to send them. Like it might take posts/show/how-to-make-a-cms and do something like:
$o = new Posts();
$o->show("how-to-make-a-cms");
If you do it that way, I think you can avoid mod_rewrite entirely as long as you're willing to accept only slightly pretty URLs, like this:
mysite.com/main.php?/posts/show/how-to-make-a-cms
I haven't done this type of thing before (because the frameworks do it so beautifully already), so I might be missing some minor details.
You should watch some tutorials from phpacademy.org or thenewboston.org, they have best and most valuable tutorials ever made about PHP.
I think you may try to start from that course/playlist:
phpacademy.org: PHP Tutorials: Creating a Blog
If you don't understand everything, watch this:
thenewboston.org: Official Beginner PHP Tutorials Playlist!
If you have no problems with PHP itself you may try to use some simple framework with MVC support. That helps A LOT in variable handling between pages, makes work with database easier etc.
phpacademy.org: Introduction to CodeIgniter
phpacademy.org: Introduction to CodeIgniter - Basic Website
I had the same problem. You can easily do this by using the fopen function. Here is a link to a tutorial: http://www.tizag.com/phpT/filecreate.php
<?php
function wwwcopy($link,$file)
{
$fp = #fopen($link,"r");
while(!feof($fp))
{
$cont.= fread($fp,1024);
}
fclose($fp);
$fp2 = #fopen($file,"w");
fwrite($fp2,$cont);
fclose($fp2);
}
//Example on using this function
wwwcopy("http://www.domain.com/list.php?member=sample", "sample.html");
//Another example
wwwcopy("http://www.domain.com/list.php?member=sample2", "sample2.html");
?>
I'm trying to develop a invoice printing module for the application we're creating (in PHP & Javascript). The thing is... I want our clients to be able to customise their invoice output as in being able to choose where to put their logo and header, how to organize their data output, etc.
I know how I want to do it, but what I don't know is how to put it into practice, so my question is: is there any Javascript or PHP class/module providing an editable canvas/layout? (so I can allow my customers to custom design their documents or reports).
Something being able to handle <div></div> blocks in a graphical way, similar to what tag editors do, returning a serialized array or something like that... well, anything would actually do, as long as I'm able to integrate it in our codebase, but that's the question...
I couldn't find anything like what you are looking for but it shouldn't be too hard to create one.
I wouldn't go for a canvas based solution but rather on an absolutely positioned DIVs with drag and drop functionality and inline content editing.
You can easily serialize the content and position of the DIVs using Ajax.
The tutorial here is not what you are lookign for but it's the first step in the way: http://devheart.org/articles/jquery-customizable-layout-using-drag-and-drop/
update
Obviously this: http://jqueryui.com/demos/draggable/ is also an important reference
I'm building a website for a restaurant and they want to be able to update their menu frequently.
I don't want to use a full-blown CMS, rather I would like to do something a lot more specific and simple.
I've decided on using an XML file to store the menu data. The XML structure is as follows:
<menudata>
<dish>
<name>Seafood Linguini</name>
<description>Scallops, shrimp, and lobster pieces on linguini in white sauce</description>
<price>24.50</price>
</dish>
. . . <!-- more dishes -->
</menudata>
I've written PHP that gets the data and displays it.
Now I need to write ‘admin’ software that they can access and edit the data. I want it to be very limited. Really, I want it to be just input fields on a blank page allowing access to editing each child of <dish>, a button to add a new <dish>, and a Save button. In an ideal world, I would like to write some JavaScript that would allow them to drag and drop the menu items into order (is that even possible?)
I am a designer, not a developer, and my PHP knowledge is limited — that said, I wrote the code for getting the XML file and echoing it into a proper HTML page in about an hour with just the php.net manual. I’m using the SimpleXML method.
So, if it’s something that’s not hard to do I can probably hack it together myself.
I have two questions:
Is what I want possible with PHP and SimpleXML? Would someone with little to no experience in PHP but a quick learner be able to do this on their own?
Is there software or code out there that I could adapt to my needs? I’ve looked around but have not found anything like it.
I know you said you did not want a CMS, but I would use drupal.org.
You will end up needed more features. How are you going to allow only certain people to edit the XML?
By doing the XML editing yourself you have to deal with issues with bad XML, unsafe data entered into the form etc.
Using a tool like drupal lets you concentrate on your design - not coding.
I want to understand how to use templating system and permalinks on php websites :D !..
let me describe my self more,
1.currently i have 20 files each have its own php logic (index.php,wizard.php,search.php etc)
ALL use same class's and includes.(install.php include all the required for all class's in my project abd u require_once(install.php) in all files)
i wana remodel my website into.
Analyze URL requested ---> IDENTIFY requested page ---> GET TEMPLATE for THIS PAGE -->MODIFY header(meta) and footer(javascript) ---> add logic ---> display page :D.
can some one put me on right learning track :D !. cuz i hv coded my website fully in oop and made all its content loads dynamically from MYSQL (simple small CMS) but i have no clue how to join template and php into index without repeating my self and create different file for each page in my web ! (each file do different jobs of course like file users.php does login and registration and userprofile etc)
Hope my english wassnt too too bad and u could understand my question :D !
My current approach so far:
Mysql table : page_tbl
columns: pagename,LogicFile,templateFile,MetaTag.
index.php?pagename
will check if not already cached or not listed for chacing it will :
Mysql:SELECT * WHERE pagename='$_GET['page']'
loginfiles = cars.php,search.php (will be exploded with , and included)
Template files = will be also exploded and modified according to MetaTag.
Metatag: Serialized assoc array with ['name']=['value'];
Then i start buffer output , replace template with new descriptions and keywords(auto generated)
include logic files
include footer.php (which include the scripts)
am i near to correct rout or still far away ? or am did i lose my track and over killing
If you are unsure whether you want to write your own, or use an existing one.
It is going to be a quite possibly very rewarding experience but a very time consuming one to write your own.
If you have a task at hand that you need to be solved, use an existing one.
That being said there are plenty of templating systems, smarty being the most long-lived one. You can find a short discussion on 5 popular ones at phpbuilder.
You also have entire Frameworks that you might want to consider. They are more than just a templating system, where database stuff, ajax helpers etc are included. Zend, CakePHP, and Codeigniter being popular ones. You can find comparisons of these at phpframeworks.
The best way is to take this route:
parse request data
determine controller which will be used
in controller select layout and template [layout "includes" template, it hold the contents that are common to all pages and template has the request-specific content]
in controller also fetch the data from database [MVP way]
assign data to array and pass it to the layout, it'll pass the data futher to the template
in layout and template use data from that array and construct view
pass everything to the browser
This is the way the frameworks work, and it isn't that bad. ;]