0

Any good resources on this?

Ideally a tutorial or walkthrough of an application being designed from the ground up or even just tutorials on the inns and outs of the framework.

I have a lot of php scripts and jquery is used to update various containers on the page. I have the Auth Module working and the homepage is displaying, but where do i start in terms of converting all those php scripts into MVC compliant code?

Currently, the majority of my scripts work similar to this example:

$.post('/scripts/getUserInfo.php', { id:id },
    function(output){
        $('div#user_info_container').html( output );
    }
);

QUESTION:

What are the steps involved in creating MVC compliant code from php scripts? Do you start by writing a controller for each script?

Am relatively new to Cake so any advice appreciated guys...

1 Answer 1

1

Write one controller and create one action for every script, where You query data from DB. For each action You will have to add a view with html output from Your previous script.

But it very much depends on Your DB model structure - if Your scripts updates data from different tables, probably You should create actions in apriopiate controllers (connected with that table model).

You can check $this->isAjax() in You controller[s] and change render layout to minimalistic (without page layout)

Sign up to request clarification or add additional context in comments.

5 Comments

ok, so if i have a script that uses say the users table, then do I place the action in the users_controller, or do I create a new controller for that particular script??
OK, if Your scripts are connected to different tables - put actions in apriopiate controllers and use different layout (like 'ajax') to render such actions
Ok, thats good advice. If you look at the sample code I posted, how do I connect to a controller from the above code? If you could post a sample that would be great.
$.post('/users/getinfo', { id:id }, function(output){ $('div#user_info_container').html( output ); } );
I would move id parameter into url (more cakeish way): $.post('/users/getinfo/'+id, function(output){ $('div#user_info_container').html( output ); } );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.