Re: Custom SQL and Populating Form
So far, I'm simply doing this: $myarr = $this->query($sql, $params, false); return $myarr[0]; I have to figure out what to do when there are no records returned. The index is wrong when that happens. On Dec 23, 2:50 pm, cricket wrote: > On Thu, Dec 23, 2010 at 8:38 AM, Dan wrote: > > Here is some code: > > > Model: > > class Project extends AppModel { > > var $name = 'Project'; > > var $primaryKey = 'project_id'; > > > function customFunction($id=0){ > > $sql = "custom sql... where project_id = ?"; > > $params = array( customValidation($id) ); > > return $this->query($sql, $params, false); > > } > > } > > > Controller: > > class ProjectsController extends AppController { > > var $name = 'Projects'; > > > function test($id=0){ > > $this->data = $this->Project->testByID($id); > > } > > } > > > View: > > echo $form->create("Project"); > > echo $form->input('project_name'); > > echo $form->end(); > > > ISSUE: > > > The controller's action with the custom SQL doesn't populate the form. > > I figured out that It's due to the array not being in the proper > > format: > > > Custom query: Array ( [0] => Array (...) > > CakePHP built in actions (ie. read() ): Array ( [Project] => Array > > (...) > > > Is there a way to have the custom SQL be returned in the proper format > > and populate the form? > > You could build the array yourself based on the result then return > that from your model. > > Or, you could use Cake's find() instead. If there's something specific > keeping you from doing that, perhaps there's asimpler workaround than > using query(). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Custom SQL and Populating Form
On Thu, Dec 23, 2010 at 8:38 AM, Dan wrote: > Here is some code: > > Model: > class Project extends AppModel { > var $name = 'Project'; > var $primaryKey = 'project_id'; > > > function customFunction($id=0){ > $sql = "custom sql... where project_id = ?"; > $params = array( customValidation($id) ); > return $this->query($sql, $params, false); > } > } > > Controller: > class ProjectsController extends AppController { > var $name = 'Projects'; > > function test($id=0){ > $this->data = $this->Project->testByID($id); > } > } > > View: > echo $form->create("Project"); > echo $form->input('project_name'); > echo $form->end(); > > ISSUE: > > The controller's action with the custom SQL doesn't populate the form. > I figured out that It's due to the array not being in the proper > format: > > Custom query: Array ( [0] => Array (...) > CakePHP built in actions (ie. read() ): Array ( [Project] => Array > (...) > > Is there a way to have the custom SQL be returned in the proper format > and populate the form? You could build the array yourself based on the result then return that from your model. Or, you could use Cake's find() instead. If there's something specific keeping you from doing that, perhaps there's asimpler workaround than using query(). Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Custom SQL and Populating Form
Here is some code: Model: class Project extends AppModel { var $name = 'Project'; var $primaryKey = 'project_id'; function customFunction($id=0){ $sql = "custom sql... where project_id = ?"; $params = array( customValidation($id) ); return $this->query($sql, $params, false); } } Controller: class ProjectsController extends AppController { var $name = 'Projects'; function test($id=0){ $this->data = $this->Project->testByID($id); } } View: echo $form->create("Project"); echo $form->input('project_name'); echo $form->end(); ISSUE: The controller's action with the custom SQL doesn't populate the form. I figured out that It's due to the array not being in the proper format: Custom query: Array ( [0] => Array (...) CakePHP built in actions (ie. read() ): Array ( [Project] => Array (...) Is there a way to have the custom SQL be returned in the proper format and populate the form? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en