Welcome Guest, Not a member yet? Register   Sign In
How to automatically generate new pages in a CRUD app?
#1

[eluser]Apocryphon[/eluser]
More precisely, a CR app? I'm having a site where the user inputs information about music albums on the Create view (a form). The form would have a field for band names. Then, in the Read view, there would be an index of bands in alphabetical order. This index would be populated with links to band pages that were automatically generated from information submitted from the Create form. How would I go about doing that? Is it even feasible? How could I use CodeIgniter to automatically create pages based on user submissions?

Or would it be more secure to create those pages manually?
#2

[eluser]sean_THR[/eluser]
All the band data will be stored in a DB, so you just need to pull it based on the URI. Someone might visit http://www.yoursite.com/band/detail/yourband. That will be directed to the band controller, the detail method, with the parameter yourband. Then you just need to query the DB for that specific band's info and output it to the page.
#3

[eluser]Apocryphon[/eluser]
I see- so instead of automatically generating a new band page every time a record with a new band is added to the database, I should just have a generic "display band" page instead? So when someone clicks on a band name on the index, the same page is always used; however, the information it brings out from the db is different depending on the band. Is that what you mean?
#4

[eluser]sean_THR[/eluser]
Yep, exactly. You'll have some sort of generic view file and you will pass the band information to it:
Code:
<h1>&lt;?php echo $band_name;?&gt;</h1>
<p>&lt;?php echo $band_information;?&gt;</p>
<p>&lt;?php echo $genre;?&gt;</p>

etc., etc.
#5

[eluser]Apocryphon[/eluser]
Sounds good... and it seems like I would have to manually update the index every time a user enters in a record with a new band. However, I guess that's not too much trouble- I guess I should do this anyways, because there could be malicious users who enter in invalid records, and I do plan on inspecting each record after submission.
#6

[eluser]sean_THR[/eluser]
You could automatically generate the band index in the same fashion. Just pull all the band names from the DB and loop through them in the view. If you're worried about malicious entries, you could just add a new column to the DB, "approved," that you could set to either true or false - default to false, and then you could set it to true after you reviewed it.
#7

[eluser]Apocryphon[/eluser]
Okay, thanks a lot for our advice! I'm hammering out the backend, the db, right now.

However, I have an issue with the frontend: right now, I'm just having a field on my form where the user can enter in the band associated with the album. However, if there was an album with multiple bands associated with it, how would I parse that entry? Is there anything in CodeIgniter that can read in an entry from a form and then parse it for multiple values separated by a delimiter (such as a comma)?
#8

[eluser]sean_THR[/eluser]
You can use PHP's explode() function to turn a delimited string into an array.
#9

[eluser]Apocryphon[/eluser]
Thank you so, so much for your assistance. You guidance has been really really helpful to me. Yet another question: as far as the MySQL database is concerned, I'm creating three tables to handle the many-to-many relationship (bands, albums, and albums_bands). Do you have any tips as to how I should handle this in CI? Would installing an ORM such as DataMapper be necessary? Or would it just be simpler to deal with SQL calls to the db directly?
#10

[eluser]sean_THR[/eluser]
I've never used an ORM - mostly due to laziness! I don't have the motivation to install and learn an ORM because I can't say I've ever needed it.

Someone else here may be better suited to answer that question.




Theme © iAndrew 2016 - Forum software by © MyBB