On 13.10.2010, at 17:07, Vikram Vaswani wrote: > Hello all > > Please can you assist with two questions: > > 1. I'm Doctrine 1.2 models with my Agavi app. However I keep getting > error about being unable to find some BaseXXX classes. On debugging > this, I realized that it has something to do with the sequence in > which classes are being loaded. In my models directory, I have classes > like: > > Author.php > AuthorTitle.php > BaseAuthor.php > BaseAuthorTitle.php > BaseCollection.php > Collection.php > > It seems these files are being loaded in alphabetical order, and so > the first two files are throwing errors as the Base classes that they > extend are not yet loaded. This error does not occur with the > Collection class...I assume because BaseCollection loads first (B) and > then Collection (C) loads, so there is no issue with the inheritance. > > I am currently working around the problem by adding the two BaseA... > classes to autoload.xml: > > <autoload > name="BaseAuthor">%core.lib_dir%/doctrine/BaseAuthor.php</autoload> > <autoload > name="BaseAuthorTitle">%core.lib_dir%/doctrine/BaseAuthorTitle.php</autoload> > > However this is clearly not a great solution. Can anyone suggest how > to fix this?
Sounds like a Doctrine problem. There is some sort of attribute
(ATTR_MODEL_LOADING_AGGRESSIVE or something) to do this, but I think you need
to register an autoloader for your Doctrine stuff or so that handles this...
> 2. In a form, I offer the user a choice of authors to link to a book.
> The user must select one author and can optionally select more than
> one. My form code looks something like this:
>
> <label for="aid">Author:</label>
> <select id="aid" name="aid[]">
> <?php foreach ($t['authors'] as $a): ?>
> <?php echo "<option value=\"$a[id]\">" . sprintf('%s, %s',
> $a['lname'], $a['fname']) . "</option>"; ?>
> <?php endforeach; ?>
> </select>
> <select id="aid" name="aid[]">
> <option value="">--none--</option>
> <?php foreach ($t['authors'] as $a): ?>
> <?php echo "<option value=\"$a[id]\">" . sprintf('%s, %s',
> $a['lname'], $a['fname']) . "</option>"; ?>
> <?php endforeach; ?>
> </select>
> <select id="aid" name="aid[]">
> <option value="">--none--</option>
> <?php foreach ($t['authors'] as $a): ?>
> <?php echo "<option value=\"$a[id]\">" . sprintf('%s, %s',
> $a['lname'], $a['fname']) . "</option>"; ?>
> <?php endforeach; ?>
> </select>
>
> Can someone suggest how I should validate this? With my current
> validation (see below), Agavi throws a validation error unless all
> three author fields are mandatorily filled. I need to change this to
> throw an error only if none of them are filled, but to accept one or
> more values. Current validator is:
>
> <validator class="number">
> <arguments base="aid[]">
> <argument />
> </arguments>
> <errors>
> <error>ERROR: Author is invalid</error>
> </errors>
> <ae:parameters>
> <ae:parameter name="type">int</ae:parameter>
> <ae:parameter name="required">true</ae:parameter>
> <ae:parameter name="min">1</ae:parameter>
> </ae:parameters>
> </validator>
>
> Thanks for any help,
<validator class="arraylength">
<argument>aid</argument>
</validator>
<validator class="number" required="false">
<arguments base="aid[]"><argument /></arguments>
</validator>
You should, however, implement a MyProjectAuthorValidator that actually looks
at the database to determine if the author exists (and that also exports the
retrieved object to the request data so you don't have to fetch it again in the
action)
- David
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
