Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-05 Thread Nick Lo

Hi Rob,

No problem, I didn't feel belittled. I'd presumed you'd skimmed over  
it and shot off a reply. Just shows you're busy but still eager to help!


Thanks,

Nick


I like the way you say "nowadays" in an "well yes, that was how we  
used
to do it back in the day, but of course, the modern way is..."  
kind of

way ;-)

Yeah, as you'll have seen I did get to that further down that post



Sorry. Didn't notice :(

I wasn't actually trying to belittle you!

Regards,

Rob...


Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-05 Thread Rob Allen
Nick Lo wrote:
> Hi Rob,
> 
>> Nowadays, you should override Zend_Controller_Action::init() rather than
>> override the constructor. Zend_Controller_Action::__construct() calls
>> init() as the last thing it does.
> 
> I like the way you say "nowadays" in an "well yes, that was how we used
> to do it back in the day, but of course, the modern way is..." kind of
> way ;-)
> 
> Yeah, as you'll have seen I did get to that further down that post
> 

Sorry. Didn't notice :(

I wasn't actually trying to belittle you!

Regards,

Rob...


Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-05 Thread Matthew Weier O'Phinney
-- Nick Lo <[EMAIL PROTECTED]> wrote
(on Tuesday, 05 December 2006, 08:51 PM +1100):
> Hi Rob,
> 
> >Nowadays, you should override Zend_Controller_Action::init() rather  
> >than
> >override the constructor. Zend_Controller_Action::__construct() calls
> >init() as the last thing it does.
> 
> I like the way you say "nowadays" in an "well yes, that was how we  
> used to do it back in the day, but of course, the modern way is..."  
> kind of way ;-)
> 
> Yeah, as you'll have seen I did get to that further down that post
> 
> >Alternatively, you could override  
> >Zend_Controller_Action::preDispatch()
> >which gets called directly before each Action function.
> 
> That sounds like both init and preDispatch now have similar  
> roles ...what distinguishes the two?

init() happens at object instantiation, which happens before
preDispatch() -- it's basically provided so that you don't need to
override the constructor, and thus possibly forget to set the request,
response, and other parameters (as you discovered the hard way).

Theoretically, if something goes wrong during the initialization
sequence, you could throw an exception, in which case the preDispatch()
will not be called -- this may be handy so that you can, for instance,
setup your models, etc., and, if unavailable, prevent the action from
dispatching. preDispatch() might then actually use the models to do some
determination of whether or not to skip the current action.

-- 
Matthew Weier O'Phinney
PHP Developer| [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/


Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-05 Thread Nick Lo

Hi Rob,

Nowadays, you should override Zend_Controller_Action::init() rather  
than

override the constructor. Zend_Controller_Action::__construct() calls
init() as the last thing it does.


I like the way you say "nowadays" in an "well yes, that was how we  
used to do it back in the day, but of course, the modern way is..."  
kind of way ;-)


Yeah, as you'll have seen I did get to that further down that post

Alternatively, you could override  
Zend_Controller_Action::preDispatch()

which gets called directly before each Action function.


That sounds like both init and preDispatch now have similar  
roles ...what distinguishes the two?


Thanks,

Nick


Ingredients Australia

http://www.ingredients.com.au




Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-05 Thread Rob Allen
Nick Lo wrote:

> 
> Anyway, I finally narrowed it down...
> 
> Before I was first extending Zend_Controller_Action with a general file
> something like:
> 
> class IndexController extends Zend_Controller_Action
> {
> public function __construct()
> {
> parent::__construct();
> do general stuff like get common objects from the registry
> }
> }
> 
> ...then using that for more specific controller files...
> 
> class ArticlesController extends IndexController
> {
> public function __construct()
> {
> parent::__construct();
> do articles specific stuff like get Zend_Db_Table stuff
> }
> }   


Nowadays, you should override Zend_Controller_Action::init() rather than
override the constructor. Zend_Controller_Action::__construct() calls
init() as the last thing it does.

Alternatively, you could override Zend_Controller_Action::preDispatch()
which gets called directly before each Action function.


Regards,

Rob...


Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-04 Thread Nick Lo

Hi Martel,

2077 is not related to controller in any way but let's try  
resolving your problem.


I was just using it as a point of reference as in "I'm currently  
using svn checkout 2077".


I'm using incubator version of Zend_Config which, according to the  
wiki manual, should be instantiated using Zend_Config_Ini alone:


$config = new Zend_Config_Ini(
'../application/configuration/routes.ini.php', 'development');


Thanks for pointing that out. I wasn't having issues with config so  
I'd not kept up with changes.


Anyway, I finally narrowed it down...

Before I was first extending Zend_Controller_Action with a general  
file something like:


class IndexController extends Zend_Controller_Action
{
public function __construct()
{
parent::__construct();
do general stuff like get common objects from the registry
}
}

...then using that for more specific controller files...

class ArticlesController extends IndexController
{
public function __construct()
{
parent::__construct();
do articles specific stuff like get Zend_Db_Table stuff
}
}

Then on the upgrade the __construct needed the response and request  
objects passed so I did this:


class IndexController extends Zend_Controller_Action
{
public function __construct()
{
parent::__construct( new Zend_Controller_Request_Http, new  
Zend_Controller_Response_Http );

do general stuff like get common objects from the registry
}
}

...and THAT was where the problem was occurring as the request object  
in ArticlesController did not then contain the params.


The correct way to do it is to use the new init() function...

class IndexController extends Zend_Controller_Action
{
public function init()
{
do general stuff like get common objects from the registry
}
}

class ArticlesController extends IndexController
{
public function init()
{
parent::init();
do articles specific stuff like get Zend_Db_Table stuff
}
}

Ah ...the relief of getting there in the end, now to actually get on  
with the app!


Thanks for your help,

Nick


Ingredients Australia

http://www.ingredients.com.au





Re: [fw-general] SVN 2077: Getting parameters from route

2006-12-04 Thread Martel Valgoerad

Nick Lo wrote:

SVN checkout 2077 seems to have broken the ability to get parameters  
from a rewrite route url (that or I've been doing it all wrong)...


2077 is not related to controller in any way but let's try resolving your 
problem.


In index.php:
$router = new Zend_Controller_RewriteRouter;
$route_config = new Zend_Config( new Zend_Config_Ini( '../application/ 
configuration/routes.ini.php', 'development' ) );

$router->addConfig( $route_config, 'routes' );


I'm using incubator version of Zend_Config which, according to the wiki manual, 
should be instantiated using Zend_Config_Ini alone:


$config = new Zend_Config_Ini(
'../application/configuration/routes.ini.php', 'development');

Old library used to do ZCI::load:

$config = new Zend_Config(Zend_Config_Ini::load(
'../application/configuration/routes.ini.php', 'development'));

Have I missed something in between?

Check if you have any routes loaded after $router->addConfig call.


In controllers/ArticlesController.php:

public function viewAction()
{
 print_r( $this->_request->getParams() );
 echo $this->_getParam( 'ref' );
}


Should work just fine but I'll double check it in a minute... and it works for 
me:

URL:
http://test.localhost/news/2

INI:
routes.newsitem.route = "news/:id"
routes.newsitem.defaults.controller = "news"
routes.newsitem.defaults.action = "show"
routes.newsitem.reqs.id = "\d+"

Controller:
public function showAction()
{
var_dump($this->_request->getParams());
}

Result:
array(3) {
  ["id"]=>
  string(1) "2"
  ["controller"]=>
  string(4) "news"
  ["action"]=>
  string(4) "show"
}


Nick


--
Michael Minicki aka Martel Valgoerad | [EMAIL PROTECTED] | 
http://aie.pl/martel.asc
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"If you pick up a starving dog and make him prosperous, he will not bite you.
This is the principal difference between a dog and a man." -- Mark Twain