Re: Can CakePHP do this? - Two

2007-01-04 Thread Martin Schapendonk


2007/1/3, skyblueink [EMAIL PROTECTED]:

I have no choice but to call $this-set() one thousand times in
Controller, and write foreach statement one thousand times in View.


Maybe you could make myfunction() a little bit more intelligent?

function myfunction($i) {
  switch($i)
  {
case 1:
  $result[0] = 'lemon';
  $result[1] = 'banana';
  $result[2] = 'apple';
  $return = array('title' = 'Fruits are here', 'things' = $result);
  break;
case 2:
  $result[0] = 'lion';
  $result[1] = 'tiger';
  $result[2] = 'monkey';
  $return = array('title' = 'Animals are here', 'things' = $result);
  break;
case 3:
  $result[0] = 'red';
  $result[1] = 'blue';
  $result[2] = 'green';
  $return = array('title' = 'Colors are here', 'things' = $result);
  break;
  }
  return $return;
}

Your controller can call myfunction() any number of times you like,
collect all arrays and make them available to the view.

In the controller:

function pass() {
  $result = array();
  for ($i = 1; $i = 3; $i++) {
 $result[] = $this-Test-myfunction($i);
  }
  $this-set('results',$result);
}



In the view:

foreach($results as $result) {
 echo Header: . $result[title];
 foreach($result[things] as $thing) {
   echo $thing;
 }
}

Not quite sure what you are trying to accomplish, however.

Martin

--
 Martin Schapendonk, [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-04 Thread skyblueink


Thanks, Martin. I'll try your suggestion.
What I am trying to accomplish was posted here today.

http://groups-beta.google.com/group/cake-php/browse_thread/thread/8968aaa372cc1e67

Any comments will be much appreciated.

On 1 4 ,   9 47 , Martin Schapendonk
[EMAIL PROTECTED] wrote:

2007/1/3, skyblueink [EMAIL PROTECTED]:

 I have no choice but to call $this-set() one thousand times in
 Controller, and write foreach statement one thousand times in View.Maybe you 
could make myfunction() a little bit more intelligent?

function myfunction($i) {
   switch($i)
   {
 case 1:
   $result[0] = 'lemon';
   $result[1] = 'banana';
   $result[2] = 'apple';
   $return = array('title' = 'Fruits are here', 'things' = $result);
   break;
 case 2:
   $result[0] = 'lion';
   $result[1] = 'tiger';
   $result[2] = 'monkey';
   $return = array('title' = 'Animals are here', 'things' = $result);
   break;
 case 3:
   $result[0] = 'red';
   $result[1] = 'blue';
   $result[2] = 'green';
   $return = array('title' = 'Colors are here', 'things' = $result);
   break;
   }
   return $return;

}Your controller can call myfunction() any number of times you like,
collect all arrays and make them available to the view.

In the controller:

function pass() {
   $result = array();
   for ($i = 1; $i = 3; $i++) {
  $result[] = $this-Test-myfunction($i);
   }
   $this-set('results',$result);
 }

In the view:

foreach($results as $result) {
  echo Header: . $result[title];
  foreach($result[things] as $thing) {
echo $thing;
  }

}Not quite sure what you are trying to accomplish, however.

Martin

--
  Martin Schapendonk, [EMAIL PROTECTED]



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-04 Thread Martin Schapendonk


In that case, my solution won't help you very much. Output is only
sent to the browser after the view is generated. You may be able to
speed up that process, but it is still being sent to the browser
afterwards.

Perhaps you can use AJAX for partial rendering, or cache the results
(or a combination of both).

Martin


--
 Martin Schapendonk, [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-03 Thread skyblueink



but I'm not sure how your doing your
sequential outputs, or how you are calling pass.

Yeah, that's the problem, and I think it maybe the limitation of
CakePHP or in general  MVC frameworks.
In actual, we can't get the desired output since we can't do the
sequential outputs, call pass().


On 1 3 ,   5 35 , TJSingleton [EMAIL PROTECTED]
wrote:

This gives the desired output, but I'm not sure how your doing your
sequential outputs, or how you are calling pass.

VIEW:
?php
echo $heading;
$count = count($results);
foreach ($results as $result) {
 echo $resultbr /;}?

CONTROLLER:
?php
class TestsController extends AppController {
  var $name = 'Tests';

  function pass($i) {
$this-set('results', $this-Test-myfunction($i));

  $i += -1;
  switch($i)
 {
case 0:
$heading = 'Header 1: Fruits are here. br /';
break;
case 1:
$heading = 'Header 2: Animals are here. br /';
break;
case 2:
$heading = 'Header 3: Colors are here. br /';
break;
 }
$this-set('heading', $heading);
  }

}?



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-03 Thread TJSingleton



In actual, we can't get the desired output since we can't do the
sequential outputs, call pass().


ok, so is this what you mean?

VIEW
Header 1: Fruits are here. br /
?php
foreach ($fruits as $fruit) {
echo $fruitbr /;
}
?

Header 2: Animals are here. br /
?php
foreach ($animals as $animal) {
echo $animalbr /;
}
?

Header 3: Colors are here. br /
?php
foreach ($colors as $color) {
echo $colorbr /;
}
?

CONTROLLER:
?php
class TestsController extends AppController {
 var $name = 'Tests';

 function pass() {
   $this-set('fruits', $this-Test-myfunction(1));
   $this-set('animals', $this-Test-myfunction(2));
   $this-set('colors', $this-Test-myfunction(3));
 }

}

--
TJ Singleton
?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-03 Thread skyblueink


Thanks Chris, I'll answer you in other thread.

On 1 4 ,   6 00 , Chris Hartjes [EMAIL PROTECTED]
wrote:

On 1/3/07, skyblueink [EMAIL PROTECTED] wrote:



 Yes, surely it will give the output I wanted. Thank you for your work,
 but what if I have to call myfunction one thousand times?

$this-set('fruits', $this-Test-myfunction(1));
$this-set('animals', $this-Test-myfunction(2));
 .
$this-set('colors', $this-Test-myfunction(1000));

 I have no choice but to call $this-set() one thousand times in
 Controller, and write foreach statement one thousand times in View.Might I 
humbly suggest that perhaps the structure of your application
may need to change. I'm trying to understand what it is you are trying
to accomplish here and would like some more info.

--
Chris Hartjes

The greatest inefficiencies come from solving problems you will never have.
-- Rasmus Lerdorf

@TheBallpark -http://www.littlehart.net/attheballpark
@TheKeyboard -http://www.littlehart.net/atthekeyboard



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-02 Thread TJSingleton



skyblueink wrote:

I want to show progress indicator to the user of my program for each
run of $i for loop of pass(). The pass() function could be modified
like the following(see below), but it does not give the expected
results since $message and $result are overwritten repeatedly. This
time I don't want to merge array of fruits, animals, and colors as I
did previously. I want to make Controller output each array into View.
this kind of job was easy when design and logic were not seperated, but
now that logic(Controller) and design(View) are seperated, and it doen
not seem to be so easy at least to me.
Could anyone show me how to modify the Controller and View?


I am completely lost as to the aim of what you are trying to do, or if
this answers it. But to simply pass the results to the view loop which
you can modify for the headers (I wouldn't even use a loop there. But I
don't know what you're trying to do.) just modify the controller as
follows.

Controller:
function pass($i) {
   $this-set('result', $this-Test-myfunction($i));
}

--
TJ Singleton


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can CakePHP do this? - Two

2007-01-02 Thread TJSingleton



skyblueink wrote:

Without using CakePHP or any other MVC framework, I would have
codedlike the following:


Can you give me an example of the final output you'd like it to
achieve? 


--
TJ Singleton


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---