[Catalyst] Anyone with PHP / Smarty Background

Brian catalyst at gzmarketing.com
Fri Dec 29 06:16:34 GMT 2006


Thank you!

That is exactly the information and head start I was after.

Now I have to name my first born son Christopher.  3 daughters so far, 
so you may have to settle for Christina.

Thanks again,
Brian


Christopher Heschong wrote:
> Yep.  The one thing that confused me and has confused every new 
> developer on my team is the "View" in Catalyst's 
> Model/View/Controller.  They always expect that's where they'll 
> generate the HTML or whatever, ala PHP.  This isn't exactly the case.  
> 99% of the time you'll have Catalyst create a Template Toolkit view 
> for you, which will basically be empty.  That's the only code 
> (usually) that will go in your Yourapp/lib/Yourapp/View/ directory.  
> What you're likely to  expect the "View" part to be is really the 
> template files you put in the Yourapp/root/ directory, and that's not 
> always clear at the start.  These template files are to some extent 
> the "View", but they don't sit in the View directory.  Getting a good 
> grasp of the MVC structure of Catalyst is key.
>
> Basically most of the actual perl code you write won't display 
> anything, it will just set variables in the stash, and your template 
> files (in root) will display those variables.
>
> The Intro in the Catalyst manual is pretty good:
>
> http://search.cpan.org/dist/Catalyst-Manual/lib/Catalyst/Manual/Intro.pod
>
> Tons of info on the Catalyst Wiki (some of it out of date):
>
> http://dev.catalystframework.org/wiki
>
> Tons of example code here:
>
> http://dev.catalystframework.org/browser/trunk/examples
>
> Another handy example:
>
> http://www.herlpacker.co.uk/tech/development/projects/parley/
>
> And this is fun:
>
> http://search.cpan.org/search?m=all&q=Catalyst+Plugin 
> <http://search.cpan.org/search?m=all&q=Catalyst+Plugin>
>
>
> When I was learning TT, it took me a while to realize that the docs 
> weren't in the Template pod, it was in the Template::Manual::* pod docs:
>
> http://search.cpan.org/dist/Template-Toolkit/lib/Template/Manual/Intro.pod
> http://search.cpan.org/dist/Template-Toolkit/lib/Template/Manual/Syntax.pod
>
>
> For PHP-style parameter arrays, take a look at 
> Catalyst::Plugin::Params::Nested:
>
> <input name="search[name]" />
> <input name="search[address]" />
>
> turn into a hashref you can pass around, or access directly:
>
> my $foo = $c->req->param('search');
> $foo->{name};
> $foo->{address};
>
> This is really nice when you want to do something like this:
>
> sub search : Local {
> my ($self, $c) = @_;
> $c->stash->{results} = $c->model('Something')->search(
> $c->req->param('search')
> );
> }
>
> which will basically connect to the database, do a "SELECT * FROM 
> some_table WHERE name = '<form input>'  AND address = '<form input>'", 
> grab the results, stick them in the stash, and then it's off to your 
> template (named search.tt by default since the sub is called "search") 
> to display.  Of course, in the real world you probably want to check 
> the input a little more stringently, but DBIx::Class does prevent 
> quite a few SQL-injection type attacks by using something called 
> binding... anyway, I'm getting off the subject.
>
> Hope that helps you get started.



More information about the Catalyst mailing list