Re: XML DataSource or solution

2011-02-12 Thread Carlos Paparoni
Thank you for the quick reply, I appreciate it.
I've tried what you suggested, and it is working, up to a point. Here
is the code I'm using:

DataSource - app/plugins/array_datasource/models/datasources/
array_source.php
(I've only included the relevant modifications instead of the entire
file, unless needed)

function __construct($config = array()) {
parent::__construct($config);
//Modification to read the XML file and populate the
$records array:
App::import('Core', 'Xml');
App::import('Core', 'File');
$this->FileUtil =& new File(WWW_ROOT.'files/'.'data.xml');
$this->File = $this->FileUtil->read();
$xml = new Xml($this->File);
$this->records = $xml->toArray();
}

Controller - app/controllers/registros_controller.php

class RegistrosController extends AppController {
var $helpers = array ('Html','Form');
var $name = 'Registros';

function index() {
$this->set('registros', $this->Registro->find('all'));
//My guess is that find isn't working correctly
}
}

Model - app/models/registro.php

class Registro extends AppModel {
var $name = 'Registro';
var $useTables  = false;
var $useDbConfig= 'local';
var $displayField   = 'espanol_comun';

//Note that I've copied the same code from the datasource
here. It apparently makes no difference, since I've commented them
alternatively.
/*
function __construct($config = array()) {
 parent::__construct($config);
//Modification to read the XML file and populate the
$records array:
App::import('Core', 'Xml');
App::import('Core', 'File');
$this->FileUtil =& new File(WWW_ROOT.'files/'.'data.xml');
$this->File = $this->FileUtil->read();
$xml = new Xml($this->File);
$this->records = $xml->toArray();
debug($this->records); //This works.
}*/

  var $validate = array(  'espanol_comun' => array('rule' =>
'notEmpty'),
'categoria' => array('rule' =>
'notEmpty'),
'definicion'=> array('rule' =>
'notEmpty'),
'ambito'=> array('rule' =>
'notEmpty')
 );
}

View -  adapted from the Blog tutorial - app/views/registros/index.ctp

  //Relevant foreach loop:
  

  
Html->link( $registro['Registro']
['espanol_comun'],
  array('controller' =>
'registros',
'action' => 'view',
$registro['Registro']
['espanol_comun']));
?>
 ...
  

When I display the view, I get notice errors in each field, saying
"Notice (8): Undefined index: Registro [APP\views\registros\index.ctp,
line 16]" which corresponds to the foreach loop.

Any ideas on what I'm doing wrong? If I debug $this->records from the
__construct function, I get the array just fine.
(I don't know if it's a better idea to use pastebin to link the entire
code. I would be happy to do so if necessary.)

On 12 feb, 13:51, Ryan Schmidt  wrote:
> 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:
> >  > 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 f

Re: XML DataSource or solution

2011-02-11 Thread Carlos Paparoni
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:
 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?

On 10 feb, 16:00, Carlos Paparoni  wrote:
> Hi everyone, I'm new to CakePHP and started using it in hopes of
> developing a project assigned to me in a course at my university as
> quickly as possible.
>
> The project requires that I avoid the use of databases completely,
> relying on XML files (or rather, file) to load, display, add, remove,
> search and save data.
>
> However, Cake relies mostly on databases, and while I managed to
> actually avoid the use of any, and read the XML file, I don't know
> where to go from there. I completed the blog tutorial and adapted it
> for the project (mainly the index view), but that is what I have so
> far.
>
> I was searching online for a solution, but didn't find any (except for
> code snippets here and there about writing a XML DS from scratch). I
> thought about using the Array DataSource (since I can convert the XML
> file into an array) but don't really know how exactly to implement
> that.
>
> Any ideas or suggestions? I would really appreciate some help.

-- 
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


XML DataSource or solution

2011-02-11 Thread Carlos Paparoni
Hi everyone, I'm new to CakePHP and started using it in hopes of
developing a project assigned to me in a course at my university as
quickly as possible.

The project requires that I avoid the use of databases completely,
relying on XML files (or rather, file) to load, display, add, remove,
search and save data.

However, Cake relies mostly on databases, and while I managed to
actually avoid the use of any, and read the XML file, I don't know
where to go from there. I completed the blog tutorial and adapted it
for the project (mainly the index view), but that is what I have so
far.

I was searching online for a solution, but didn't find any (except for
code snippets here and there about writing a XML DS from scratch). I
thought about using the Array DataSource (since I can convert the XML
file into an array) but don't really know how exactly to implement
that.

Any ideas or suggestions? I would really appreciate some help.

-- 
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