Friday, April 1, 2011

Re: execute query twice in a short time is a problem?

CakePHP didn't or couldn't do it that's why i was experimenting something different.


On Fri, Apr 1, 2011 at 12:25 AM, Ryan Schmidt <google-2010@ryandesign.com> wrote:
On Mar 31, 2011, at 14:52, cake-learner wrote:

> foreach( $arrEmp as $employeeObj ){
> $options = array( "survey_name" => $surveyObj[ 0 ][ 'Survey' ]
> [ 'survey_name' ] );
> $this -> Notification -> create( 'Report card is realeased','',
> $currentUser[ 'Account' ][ 'id' ], $employeeObj[ 'e' ]
> [ 'accounts_id' ], 7, "HR Department", $options );
> }
>
> /**
> * create function in Notification Component
> */
> function create( $subject, $message="", $creator, $recepient, $type =
> 0, $from, $options=null ){
> $this -> controller -> loadModel('Notification');
> $this -> controller ->  Notification -> create();
> $notification[ 'subject' ] = htmlentities( $subject );
> $notification[ 'message' ] = htmlentities( $message ) .
> $defaultMessage;
> $notification[ 'from' ] = htmlentities( $from );
> $notification[ 'creator' ] = $creator;
> $notification[ 'sentto' ] = $recepient;
> $notification[ 'type' ] = $type;
>
> foreach( $notification as $key => $value ){
>  $arrKey[] = $key;
>  $arrValues[] = $value;
> }
>
> $sql .= "INSERT INTO notifications (" . implode( ",", $arrKey ) . ")
> values (" . implode( "," , $arrValues ) . " )";
> $this -> controller ->  Notification -> Query( $sql );
> }

This looks fairly messy. Why are you writing raw SQL and not letting a CakePHP model do it for you?


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: