PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Jul 10, 2020 9:16 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Fri Dec 02, 2016 8:12 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Fri Dec 02, 2016 11:09 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 367

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Dec 03, 2016 2:28 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Dec 03, 2016 3:23 am 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 367

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Dec 03, 2016 1:45 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
I can certainly show you what I might do to convert your function findlotsAction() into an object that has more reuse and might be easier to maintain.

Here is some pseudo-code about how I think about managing forms like this. Not sure if this helps, but maybe it gives you an idea about my comments above about the kinds of separations I am thinking about.
Syntax: [ Download ] [ Hide ]
$formModel = new FormModel($request);

// configure Form Model

if ($formModel->isValid()) {
    $searchModel = new SearchModel($db, $formModel);

    $resultsView = new SearchResultsView($searchModel);

    $response->setContent($resultsView->render());
} else {
    $formView = new SearchFormView($formModel);

    $response->setContent($formView->render());
}

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Dec 03, 2016 4:52 pm 
Offline
Forum Contributor

Joined: Fri Jul 20, 2007 11:29 am
Posts: 367
I'm not concerned with the plumbing around separation of concerns. I understand it and currently going through a series of tutorials on Laravel, Symfony, & roll-your-own-mvc-with-composer.

From your example, what's going on in the SearchModel regarding generating sql and $formModel having the option of just being a simple associative array is where i'm focused.

Also not interested in auto-generating form html or displaying validation errors. This code that currently exists in 1 controller I want to turn into something that can be used in many places like a "service" or "helper" or "utility" (not sure if those are the right terms). And most of the time it won't be used in conjunction with an html form. Just create a new object, pass it a hard coded criteria array, and get the sql text or sql results array. Generating the sql from that criteria is where I feel this code is messy and buggy and probably should be using a query builder or something. I'd like to find some open source project that has a large and complex example of converting a large number of possible criteria options into a large and complex sql statement.

_________________
Warning: I have no idea what I'm talking about.


Top
 Profile  
 
PostPosted: Sat Dec 03, 2016 6:05 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Ok. I think I understand that you want the Search Model that is passed an assoc array of the form values. When I get a little time, I will try to refactor your findlotsAction() function into a class that might make it simpler and easier to maintain.

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group