Automatically Create New Pages With Content From Database
Permalink
Hi there, I really think that Concrete5 can do this and is the solution I am looking for but I really need some help to get going here.
We have a preexisting database of products. I would like to write a php script that will generate a new set of Concrete5 pages for a product using content from the database so that we only have to enter the data once. Then once the Concrete5 pages are setup we have a nice CMS to easily edit those pages in the future if need be. We do not have to have the pages sync with the database or anything fancy like that, just the initial setup is all we're after right now.
Now, I am an all out beginner with C5. What I have struggled with so far is that I cannot actually find a fully working example of how to use the C5 API. There are plenty of code snippets yes, but I do much better when I can work backwards from something that already works. If anyone can provide me with an example like that and some guidance towards what API commands I need to generate new pages that would be incredibly helpful.
Best of all if I could get a fully working script that generates a new page with the page title as a PHP variable I am sure I could figure out the rest from there.
Thank you all very much!
We have a preexisting database of products. I would like to write a php script that will generate a new set of Concrete5 pages for a product using content from the database so that we only have to enter the data once. Then once the Concrete5 pages are setup we have a nice CMS to easily edit those pages in the future if need be. We do not have to have the pages sync with the database or anything fancy like that, just the initial setup is all we're after right now.
Now, I am an all out beginner with C5. What I have struggled with so far is that I cannot actually find a fully working example of how to use the C5 API. There are plenty of code snippets yes, but I do much better when I can work backwards from something that already works. If anyone can provide me with an example like that and some guidance towards what API commands I need to generate new pages that would be incredibly helpful.
Best of all if I could get a fully working script that generates a new page with the page title as a PHP variable I am sure I could figure out the rest from there.
Thank you all very much!
You should look at this code by Jordanlev, it will teach you a lot about what you want to know
https://github.com/jordanlev/c5_package_installer_utils...
https://github.com/jordanlev/c5_package_installer_utils...
Here's a basic example of how to programmatically create pages based on external data. This is just a script I used to import data from a CSV file, but the same API stuff would be used if you were initially getting the data from another database.
I put this script (i.e. import.php) in my top level tools folder and ran it via:
http://mysite.com/index.php/tools/import...
In this script the context is importing builder profiles into a business directory.
It's quick and dirty, but it got the job done for an initial import. Be careful with the number of records you import at a time, as I found that it was quite slow (probably because there is a nicer way of doing it!).
I put this script (i.e. import.php) in my top level tools folder and ran it via:
http://mysite.com/index.php/tools/import...
In this script the context is importing builder profiles into a business directory.
<?php $file1 = "/home/mywebsite/public_html/tools/import.txt"; $lines = file($file1); $businesses = array(); // loop through csv and collect/filter data foreach($lines as $line) { $result = explode("\t", $line); array_shift($result); $name = trim($result[0], '"'); $name = ucwords(strtolower($name)); $website = $result[10]; $email = $result[9]; $businesses[] = array( 'name'=>$name,
Viewing 15 lines of 53 lines. View entire code block.
It's quick and dirty, but it got the job done for an initial import. Be careful with the number of records you import at a time, as I found that it was quite slow (probably because there is a nicer way of doing it!).
Once I figured out that I had to click the tiny "View entire code block." under the block of code you posted, your answer was very helpful and I did manage to get it working. Thanks a bunch!!
How about just a complete example of a working API call in PHP?