On Jul 4, 11:46 am, FluF <[EMAIL PROTECTED]> wrote:
> This is what i'm trying to do
>
> class FooController extends AppController{
>   var $name = "Foo";
>   var $useTable = false;
>
> };
>
> class Foo extends AppModel{
>   var $name = "Foo";
>   var $useTable = false;
>   private $text = "";
>
>   public function setText($txt){$this->text = $txt;}
>   public function getText(){return $this->text;}
>
> };
>
> /** foo.ctp **/
> <h1><?php echo $foo->getText(); ?></h1>
>
> class otherController extends AppController{
>  /* ... */
>  public $uses = array('Foo');
>
>  public function myaction(){
>    $this->Foo->set('my text');
>    $this->set('foo', 'my text');
>  }
>
> }
>
> /** otherController/myaction.ctp **/
> <?php echo $foo->render(); ?>
>
> Of course it doesn't work, beczuse in otherController, Foo is a Model
> not a controller so Foo->render() doesn't exist.
>
> maybe i have to do something like :
> public function myaction(){
>  load FooController
>  $this->FooController->Foo->setText("hello world");
>  $this->set('foo', $this->FooController);
>
> }
>
> but how can i load controller from an other controller ?

You don't load controllers from controllers. If you put the functions
to process your data in your model (where they should be) You can
simply load the model in other controllers by adding it to the $uses
array.  In the past when I have come across these types of situations
I make model methods and view elements that render them.  That way in
my controller I can do

$latest = $this->Model->getLatest();

and in my view

echo $this->element('model/latest', array('latest'));

Then I have a combined model / view fragment that can be used anywhere
in the application.

-Mark

> On Jul 3, 2:56 pm, the_woodsman <[EMAIL PROTECTED]> wrote:
>
> > There are various approaches.
>
> > One is to create a view called default_index.ctp, which refers to
> > generic names, i.e $mainModel, or something similar.
>
> > Then in your controllers, make sure you pass the data in a similar
> > format to the view, with the correct generic names, i.e
>
> > $this->set('mainModel','User');
>
> > Then, force the controllers to render the default view with $this-
>
> > >render('viewPath').
>
> > I believe scaffolding works in a vaguely similar way. But as I said,
> > there are other approaches too...
>
> > On 3 Jul, 09:44, FluF <[EMAIL PROTECTED]> wrote:
>
> > > Hello,
>
> > > I'm working on a project to display many statistics from many
> > > Models( clients, phonecalls, benefits, ..).
> > > Those statistics have the same presentation :
> > >  - html table with different CSS but the same HTML code
> > >  - ordonnable columns (not all)
> > >  - tooltips for columns
> > >  ...
> > >  - graphics using GD2
>
> > > So before i found CakePhp ( and MVC) , i wrote this:
>
> > > class ArrayToTable {
> > >  public function __construct($my2DArray, $params){
> > >     /*...*/
> > >  }
> > >  /* other functions */
> > >  public function process(){
> > >    /* do some stuff with my2DArray */
> > >  }
> > >  public function render(){
> > >    /* return the HTML code */
> > >  }
>
> > > };
>
> > > And i used
> > > $bar = new ArrayToTable($result);
> > > /* work with $bar */ ;
> > > echo $bar->render();
>
> > > I found requestAction, but i don't know if it is the correct way.
>
> > > So how can i do that with cakePHP ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to