Letractively / cfwheels

Automatically exported from code.google.com/p/cfwheels
0 stars 0 forks source link

Model, View and Controller generators #112

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to implement a generator for Wheels, but I want it to be part of 
the framework, so 
lets say I would go and call (only on development mode of course)

mysite.com/generator/?name="Blogs" and it would create the corresponding Model, 
views, 
routes and the controller with this prebuilt info

<cfcomponent extends="controller">

    <!--- blogs/ --->
    <cffunction name="index">
        <cfset blog = model("Blog").findAll()>
    </cffunction>

    <!--- blogs/id --->
    <cffunction name="show">
        <cfset blog = model("Blog").findByKey(params.id)>
    </cffunction>

    <!--- blogs/blog --->
    <cffunction name="new">
        <cfset blog = model("Blog").new()>
    </cffunction>

    <!--- blogs/create --->
    <cffunction name="create">
        <cfset blog = model("Blog").blog(params.blog)>

        <!--- Verify that the record creates successfully --->
        <cfif blog.save()>
            <cfset flashInsert(success="The record was created successfully.")> 
            <cfset redirectTo(action="show")>
        <!--- Otherwise, throw and error --->
        <cfelse>
            <cfset flashInsert(error="There was an error creating the record.")>
            <cfset redirectTo(action="new")>
        </cfif>
    </cffunction>

    <!--- blogs/id/edit --->
    <cffunction name="edit">
        <cfset blog = model("Blog").findByKey(params.id)>
    </cffunction>

    <!--- blogs/id/update --->
    <cffunction name="update">
        <cfset blog = model("Blog").findByKey(params.id)>

        <!--- Verify that the record updates successfully --->
        <cfif blog.update(params.blog)>
            <cfset flashInsert(success="The record was updated successfully.")> 
            <cfset redirectTo(action="show")>
        <!--- Otherwise, throw and error --->
        <cfelse>
            <cfset flashInsert(error="There was an error updating the record.")>
            <cfset redirectTo(action="edit")>
        </cfif>
    </cffunction>

    <!--- blogs/id/delete --->
    <cffunction name="delete">
        <cfset blog = model("Blog").findByKey(params.id)>

        <!--- Verify that the record deletes successfully --->
        <cfif blog.save()>
            <cfset flashInsert(success="The record was deleted successfully.")> 
            <cfset redirectTo(action="index")>
        <!--- Otherwise, throw and error --->
        <cfelse>
            <cfset flashInsert(error="There was an error deleting the record.")>
            <cfset redirectTo(action="index")>
        </cfif>
    </cffunction>

</cfcomponent>

I was planning on making it a folder with a blank Application.cfc in it, but I 
was wondering if 
there is a way to put it inside the wheels folder.

Thoughts?

Original issue reported on code.google.com by rierar...@gmail.com on 19 Oct 2008 at 3:51

GoogleCodeExporter commented 9 years ago
I think we need a plugin system built for Wheels first and then implement this 
as a 
plugin (which could be later turned into core code of course). 

Original comment by per.djurner@gmail.com on 19 Oct 2008 at 4:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is a simple thing I created tonight (I havent done a site yet with wheels 
but I think thats how the 
controller should look like) all it does it creates a Controller with the CRUD 
already in place and a Model in 
their representive folders.

Much more to be done, this is just the first thing that popped out of my head. 
To use it just unzip the file into 
your site and run

http://www.yoursite.com/generators/?name=ObjectName

remember to DELETE that folder on production (I still need to add conditionals 
for the 
current enviroment)

Original comment by rierar...@gmail.com on 20 Oct 2008 at 1:07

Attachments:

GoogleCodeExporter commented 9 years ago
I fixed the probelm where the model.cfc file was beign created in plural, and 
added the creating of the view 
folder and the CRUD view files as well (just a simple title with a cfdump of 
the data passed from the Controller)

Per and Chris, I hope you dont mind me uploading this here.

Original comment by rierar...@gmail.com on 20 Oct 2008 at 9:48

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by per.djurner@gmail.com on 22 Oct 2008 at 2:19

GoogleCodeExporter commented 9 years ago

Original comment by per.djurner@gmail.com on 22 Oct 2008 at 2:20

GoogleCodeExporter commented 9 years ago
Setting this to "invalid" now since we're doing it as a plugin and I don't want 
to 
include tickets for plugins in this listing.

Original comment by per.djurner@gmail.com on 29 Oct 2008 at 12:41