Wednesday, December 30, 2009

Re: Getting incremental number from the counter

I tried to do as you wrote, creating static method that generates number in
app model. But it doesn't get incremented as I press the refresh button in
the browser (new submit)
here's the code
//model post.php
class Post extends AppModel {
var $name = 'Post';
static $num = null;

static function getNumber() {
self::$num = self::$num + 1;

return self::$num;
}
}

//controller posts_controller.php
class PostsController extends AppController {
var $name = 'Posts';
function processForm() {
$no = Post::getNumber();
$this->set('no', $no);
//debug($no);
}
}

//view process_form.ctp
<?
echo "generated number is " . $no;
?>
The generated number is always 1. Does that mean that everytime I hit this
controller action (processForm), a new Post model is created and static num
variable is always set to null ?
If that is so, how can I make a method that increment number in a model ??
Thanks


John Andersen-6 wrote:
>
> Based on what you wrote, I would put the method together with the
> model that handles the registration, so that when the registration
> data have been validated, the model requests a registration number and
> saves it together with the registration data.
>
> Hope this helps ;)
> John
>
> On Dec 28, 4:08 pm, aveev <nashrullah_a...@yahoo.com> wrote:
>> Well I mistakenly wrote it as an app number. It's actually a registration
>> number.>1) What are the requirements for the application?
>>
>> So here's the process:
>> After a user is finished filling up the form, his app will be given a reg
>> number. We will store this user data along with the reg number on a table
>> (registration table).
>> And then we put this user data on pdf file, which the user can download
>> and
>> print.
>> the user will bring the printed form to our office, and then we make some
>> checks to the data. If it's ok, then we approve his application and give
>> his
>> app an app number and store it in another table (user table).
>> If his/her data doesn't pass our check, we will correct the data in our
>> office.
>>
>> This reg number will have a validity period. As of the requirement,it is
>> 3
>> years. If the applicant doesn't come within this validity period, his/her
>> record will be deleted.>a) Is the application to be available for a long
>> time?
>>
>> yes. We will keep the user data for a long time.>b) Can the application
>> expire?
>> yes.
>> >c) What information does the application contain?
>>
>> it contains about the user details (name, add, pob, dob, his/her pics,
>> and
>> id copy as an uploaded file).
>>
>> So my previous question is about generating the reg number ..Should I put
>> it
>> as a static method  in the component, model, or what ??
>>
>>
>>
>> John Andersen-6 wrote:
>>
>> > Your problem can be solved in many ways, so for me/us to better be
>> > able to help you, I have the following questions:
>>
>> > 1) What are the requirements for the application?
>> > a) Is the application to be available for a long time?
>> > b) Can the application expire?
>> > c) What information does the application contain?
>>
>> > Assuming that the application must be available for a long time
>> > (statistics, etc.) and that the application can expire (the
>> > application was granted but the user never confirmed the grant), I
>> > suggest you to store the application in a database table and to use
>> > the tables primary key as the unique application number.
>>
>> > That is just for a start! Looking forward to hearing more about your
>> > requirements :)
>> > Enjoy,
>> >    John
>>
>> > On Dec 26, 3:08 pm, aveev <nashrullah_a...@yahoo.com> wrote:
>> >> I'm newbie to cakephp..
>> >> I have this scenario.
>> >> User fills in a form. Upon finishing filling the form, his/her
>> >> application
>> >> will be given an app number. This app number comes from a counter.
>> >> So I need to make a static method that returns this app number. What I
>> >> don't
>> >> know is where I should put this method at best ??
>> >> Should I wrap it in a component (making static method in a component),
>> >> model
>> >> (making static method in a model) or what ?
>> >> Let's say If I put it in the component, here's what I've come up with
>> :
>> >> class Counter extends Object {
>> >>         static $num = 0;
>>
>> >>         static function get_num() {
>> >>             $num = $num + 1;
>> >>             return $num;
>> >>         }
>> >>     }
>>
>> >> So in controller I can call this static method like this:
>> >> class SomeController extends AppController {
>> >>   App::import('Component', 'Counter');
>> >>  some_function() {
>> >>       $app_num = Counter::get_num();}
>> >> }
>>
>> >> Is it the right way to solve my problem ??
>> >> Any help would be appreciated.
>> >> Thanks
>>
>> >> I use cakephp 1.2
>> >> --
>> >> View this message in
>> >>
>> context:http://old.nabble.com/Getting-incremental-number-from-the-counter-tp2...
>> >> Sent from the CakePHP mailing list archive at Nabble.com.
>>
>> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscribe@googlegroups.com For more options, visit this
>> group
>> > athttp://groups.google.com/group/cake-php?hl=en
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Getting-incremental-number-from-the-counter-tp2...
>> Sent from the CakePHP mailing list archive at Nabble.com.
>
> 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+unsubscribe@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php?hl=en
>
>

--
View this message in context: http://old.nabble.com/Getting-incremental-number-from-the-counter-tp26927052p26974761.html
Sent from the CakePHP mailing list archive at Nabble.com.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: