Tuesday, November 2, 2010

Re: Newbie trying to pass xml object

On Tue, Nov 2, 2010 at 12:20 AM, mochaman <mochamanbj@gmail.com> wrote:
> Let me start by saying that I am very new to php and cakephp.  I went
> through the blog tutorial (:-)) and now am facing a problem which I
> believe is something simple, but can't seem to get it to work.  I have
> an xml file which I am reading into my view then upon selection of one
> of the nodes, call my controller to display the children of that
> node.  Here are my code snippets:
>
> In my view:
>
> <?php
>                $registryFile = simplexml_load_file("../models/registry.xml");
>                $modules = $registryFile->modules;
>                foreach($modules->children() as $module)
>                {
>                        $links = $module->links;
>                        echo $this->Html->link($module-
>>name,array('action'=>'Modules','$links'));
>                        echo "<br/>";
>                }
> ?>
>
> In my controller:
>
> class MyController extends AppController {
>        function Modules($InParent)
>        {
>                echo "<dt>".$InParent."</dt>";
>                foreach($InParent->children() as $link)
>                {
>                        echo "<dd>".$link->name."</dd>";
>                }
>        }
> }
>
> I keep getting an error that "Fatal error: Call to a member function
> children() on a non-object".
> Any assistance is appreciated.

You can't pass an XML node through an HTTP request. Not like that,
anyway. And, if you're going to fetch these from a file, you'd be
better off doing it in the controller. In which case, you could then
pass a node ID to your controller function, having it fetch just those
child nodes.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: