Thursday, March 31, 2011

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

Model::create() takes an array as the first parameter.
http://api.cakephp.org/class/model#method-Modelcreate
http://book.cakephp.org/view/1031/Saving-Your-Data

On Thu, Mar 31, 2011 at 3:52 PM, cake-learner <sh.koizumi@gmail.com> wrote:
> I have a problem saving model in a loop. I am not sure the problem is
> executing
> a query twice in such a short time or how I am calling is the problem.
> I tried with $this -> controller -> Notification -> save but didn't
> work so i am trying to do with
> maunally query instead but still get the same result. only the first
> get saved but not the second one.
>
>
> 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 );
> }
>
> --
> 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: