On Feb 11, 2011, at 20:34, Carlos Paparoni wrote:

> To make an update on the situation:
> 
> I made the code work with the Array DataSource up to a point. The
> problem right now is that it uses a $records array which is assigned
> statically in the Model, like this:
> <?php
> class State extends AppModel {
>       var $name = 'State';
>       var $useDbConfig = 'local';
>       var $displayField = 'name';
>        //Here is where records are assigned to the array:
>       var $records = array(
>               array('id' => 1, 'name' => 'Alabama', 'abbr' => 'AL'),
>               array('id' => 2, 'name' => 'Alaska', 'abbr' => 'AK'),
>               array('id' => 3, 'name' => 'Arizona', 'abbr' => 'AZ')
>       );
> }
> ?>
> 
> The issue is that if I try to use a function inside the model (for
> example, one I found to read a XML file and turn it into an array), I
> get parsing errors from PHP.
> So, I'm stuck. Where should I add that functionality? Should I edit
> the datasource and have it read the XML from there?

Correct, if you want to call PHP functions, you cannot do so in the declaration 
of your class; you must do so for example in the constructor:


<?php
class State extends AppModel {
        var $name = 'State';
        var $useDbConfig = 'local';
        var $displayField = 'name';
        function __construct() {
                parent::__construct();
                // here you could populate $this->records using a function 
instead
                $this->records = array(
                        array('id' => 1, 'name' => 'Alabama', 'abbr' => 'AL'),
                        array('id' => 2, 'name' => 'Alaska', 'abbr' => 'AK'),
                        array('id' => 3, 'name' => 'Arizona', 'abbr' => 'AZ')
                );
        }
}



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to