Agavi - Random Notes

How to upload files in Agavi Framework
14:29 hi... how can i upload files in agavi? 14:29 $rd->getFile doesn't seem to work 14:38 -!- benschi [n=benjamin@78.52.189.64] has joined #agavi 14:42 simoncpu: If sent via POST executeWrite is ya friend 14:43 then in ze Action $rd->getFile('file') 14:44 but be sure to validate the file first 14:47 benschi: $rd->getFile('fieldname') returns null... 14:47 validation is set to conditional 14:48 simoncpu: I remember that there was something special about the form 14:48 let me check 14:49 enctype="multipart/form-data" 14:49 try that 14:50 

How to move uploaded file to desired location
$rd-&gt;getFile('foo')-&gt;move('/path/to/dest');

Agavi Filesize
I hope it's possible to strip down Agavi. 10K   ./model 34K   ./view 612K   ./build 728K   ./config 76K   ./controller 24K   ./core 76K   ./database 366K   ./date 96K   ./exception 106K   ./filter 52K   ./logging 200K   ./validator 56K   ./renderer 12K   ./action 60K   ./response 138K   ./routing 72K   ./storage 92K   ./testing 3.2M   ./vendor 7.4M   ./translation 24K   ./user 84K   ./util 122K   ./request

vendor/ and translation/ make up 10.6MB out of Agavi's 14MB size. PHPUnit (located inside vendor/) is not needed in production environments, and some projects require only one or two languages.

Manually specifying a template in Agavi
17:11 houmenta 17:11 in agavi, how do you guys use the same template in both your Success and Error views? 17:11 i just want to display a line of error message in my Error view 17:14 < Seldaek> $this->getLayer('content')->setTemplate('BlahSuccess'); 17:14 < Xylakant> $this->getLayer('whateverthenameofyourcontentlayeris')->setTemplate('whateverthenameofyourtemplatefileis');

Manually specifying a view in Agavi
18:53 how can i manually set the action's view? 18:53 i.e., if i do return "Success" from IndexAction, 18:53 IndexSuccessView is used; how can i use SomethingSuccessView instead? 18:56 < Jarda> array('Module', 'SomethingSuccess') could work 18:56 lemme check 18:58 Could not find file for View "SomethingSuccess" in module "Module" 18:58 * simoncpu tries specifying the subfolder 18:59 < Jarda> yeah, 'Subfolder/SomethingSuccess 19:01 cool, it works

Redirecting a page inside a Controller
18:08 i'm not sure if i'm doing this correctly, but is it advisable to redirect the page from the Controller? 18:08 i mean, do i need to create a new View just to redirect a page? 18:08 In other frameworks I do it fromt he controller, I don't see why agavi would be any different. 18:09 from the* 18:09 cool, cool 18:09 btw, i just do a setRedirect, right? 18:10 Sounds right, but check with the API 18:10 -!- icyt is now known as IcyT 18:11 -!- fnordfish [n=Adium@78.52.130.23] has joined #agavi 18:11 $this->getResponse->setRedirect works inside a view but inside a controller 18:11 i guess i need to check with the api 18:13 < _cheerios> in agavi you redirect in ze view 18:13 Ok Furhurer cheerios 18:14 mvc purists.... 18:14 mwahahahaha 18:14 heh 18:15 Mind you I guess other frameworks don't have sections for the view like agavi does 18:15 Zend's version of a view is to allow you to make a .phtml file

Zen of Agavi
17:12 ei, i have this epiphany a while ago 17:13 i realized that web app frameworks are simply web apps... there's nothing "magical" about it 17:13 then you extend the framework by adding modules 17:14 the project is a subset of the framework, not the other way around 17:14 * simoncpu speaks to the wind to talk to himself 17:14 No, a app based on a framework by definition is a superset. 17:14 Since you're adding functionality. 17:15 hmmmm 17:15 A subset would be taking a small group of the functionality provided in the framework 17:15 But with say, an agavi project, you're adding so it makes it a superset 17:16 i think a framework is a web app that you extend... it's a skeleton web app that forces you to structure your code in a specific way 17:16 since all the original functionality is there plus more 17:16 < graste^china> agavi's not a web app since you may use it as a console ab etc 17:16 < graste^china> s/ab/app/ 17:16 Yeah 17:16 ah... that makes sense 17:17 * graste^china has the epiphany, that everything is just code and can be rewritten, modified, read, deleted, forgotten and rediscovered over the years... =) 17:17 i have this perspective a while ago, that frameworks are "hidden underneath" the project 17:17 with agavi, i realized that the framework is a part of the project 17:17 something like that 17:18 an action is simply a class that inherits classes from agavi 17:18 Yeah, without a doubt 17:18 But that's how MVC should be implemented

Sessions
17:45 how do i use sessions in agavi? 17:45 < Jarda> simoncpu: via user 17:46 $this->getContext->getUser->setAttribute? 17:46 uhm... why is it called getUser? 17:46 it sounds like a specialized login system 17:46 < Xylakant> user is the abstraction for any data that outlives the request 17:47 < Xylakant> because the data is usually tied to a user 17:47 < Xylakant> it could have been called usersession or whatever, it's user because it has always been user

Models
17:05 how can i pass a parameter to its constructor, like $myclass = new MyClass('param'); ? 17:05 < Jarda> $this->getContext->getModel('MyClass', null, array('param')) 17:06 < Jarda> and in your MyClass model you create a initialize(AgaviContext $context, array $parameters) and that param will be $parameters[0] 17:07 ah, so i need to use initialize instead of __construct? 17:08 < Jarda> yeah 17:08 btw, if the 2nd param in getModel is set to null, will it automatically look for the model inside its own module? 17:08 < Jarda> no 17:08 < Jarda> then it looks in app/models/ 17:08 ah... 17:09 < Jarda> http://codepad.org/6nzaMc68 (wiki note: copied to http://simoncpu.pastebin.com/f29cf8bec) 17:10 < Jarda> I don't use constructors in my models, as I do all constructing via initialize 17:11 ah... 17:11 we need to manually call AgaviModel's initialize as well? 17:11 < Jarda> yeah, or do all the context-related stuff in you own initialize 17:17 btw, how can i get the current module name? 17:19 $container->getActionName and $container->getViewName as well 17:20 $this->getContainer->... $this->getContainer->getModuleName;

Form Population Filter
12:44 huomenta 12:44 is it possible to control where fpf would insert its error messages? 12:45 you see i have an IPv4 address field which consists of a text box and drop down box 12:45 i need to insert the messages below those two elements 12:45 instead of below the textbox 13:01 < MugeSo> simoncpu: use error_messages, field_error_messages or multi_field_error_messages parameter 13:06 thanks 13:07 < MugeSo> multi_field_error_messages is for checkbox or radiobox, filed_error_messages is for other fileds. error_messages is used for errors not related to any field. error_messages is also used if                field_error_messages or multi_filed_error_messages is not set.

Validation: Difference between Arguments and Parameters
00:11 what's the difference between arguments and parameters? 00:15 < _cheerios> same distinction as elsewhere; there's (function) arguments and (query) parameters. 00:15 < Xylakant> parameters are passed to the validator to change how it acts 00:15 < Rayne> arguments are "user input" 00:15 < Xylakant> arguments are the name of the request arguments the validator acts upon 00:16 ah, i see... 00:16 i can now see the distinction even though everything can be put into the arguments or parameters.... 00:16 arguments = what 00:16 parameters = how 00:17 < Rayne> in some cases you can define an argument's key as parameter (whithout looking up the built in validators it should be possible with the Equals validator) 00:17 < Rayne> but that is a special case

Views/Templates: Adding a Specific Text to a General Template
16:52 how do you guys solve a problem where a specific view 16:52 needs something in the header? 16:52 i mean, 16:59 the cheap way would be to set a global request attribute, that you use in the decorator/head slot as the decorator slots are rendered after the main view and its slots 16:59 but you have to be careful with your fragment caching then, as you have to cache this attribute (as it otherwise would be los in the cached version of the page) 17:00 < Xylakant> simoncpu: if you're on trunk you should set a response attribute 17:01 < Xylakant> that works nicely with fragment caching 17:01 < Xylakant> if you're on 1.0 you can set the attribute in the view's initialize method 17:01 yikes, i think i still need to read about it 17:01 i'm using 1.0 17:02 i've just set an attribute in the view 17:02 < Xylakant> the initialize method is always called, even on a cached view 17:02 but passing HTML from the view doesn't feel... right 17:02 < Xylakant> what kind of html are you passing? 17:02 basically, i need to insert external javascript and css files =) 17:09 < Xylakant> well, just set the list of required files in a request attribute 17:10 < Xylakant> do the html generation in the decorator template

Can two routes have the same name?
17:52 &lt; simoncpu&gt; huomenta 17:52 &lt; simoncpu&gt; can two routes have the same name? 17:52 &lt; xboy&gt; but event with both checked, it ain't check the title & content validator 17:52 &lt; sth&gt; simoncpu: one will overwrite the other 17:52 &lt; v-dogg&gt; simoncpu: can as in you don't get any errors, but otherwise can't

How to append in
18:12 I like to have a method in my templates like addScripts or AddStyles, so i can pass styles & scripts to this method, and then it append the files in the header of the Master template 18:13 how can i do such a thing? 18:13 by header i mean 18:13 < v-dogg> usually stuff like that is passed via AgaviRequest 18:14 < v-dogg> $this->getContext->getRequest->appendAttribute('js', 'myfoo.js'); 18:14 < v-dogg> in the view 18:15 < v-dogg> and hasAttribute('js') foreach($rq->getAttribute('js'): ?>  in Master.php 18:16 < v-dogg> trunk (soon to be 1.1, I think) has responseattributes for this which is better because request attributes can get tricky if you add caching into the mix