Re: Reusable code, components and controllers.

2006-12-26 Thread phpjoy


great, gonna use this one!

for some kinda reason, i didn't take into consideration that you can
use var $components = array( 'Session' ); in a component..

sigh! :)


--~--~-~--~~~---~--~~
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: Reusable code, components and controllers.

2006-12-25 Thread Mariano Iglesias


Why couldn't you access session from a component? Add the Session component
to the component you are creating, something like:

class FetchSessionComponent extends Object
{
var $name = 'FetchSession';

var $components = array( 'Session' );

var $uses = 'Section';

var $controller;

function startup($controller)
{
$this-controller = $controller;
}

function getSection($id)
{
if (!isset($this-Section))
{
loadModel('Section');
$this-Section = new Section();
}

$this-Section-id = $id;
$section = $this-Section-read();

		if ($section === false) 
		{

$this-Session-setFlash('Section doesn\'t exist,
displaying sections index.');

$this-controller-redirect('/admin/sections/');
}

return $section;
}
}

And then from your controllers you add FetchSession as a component and you
can do:

$section = $this-FetchSession-getSection($this-params['url']['section']);

-MI

---

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 


BAKE ON!

-Mensaje original-
De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
de phpjoy
Enviado el: Lunes, 25 de Diciembre de 2006 10:24 a.m.
Para: Cake PHP
Asunto: Reusable code, components and controllers.


I have this code for my app, and I need to put it in a few controllers.
I wonder where I can put it, so I could call it from the controllers.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---