Thursday, August 2, 2012

Re: Proper MVC location for a function and its call

With the method in the model, be sure to change this line:

$this->TopicTree->getPath(...)

to:

$this->getPath(...)


If you want the value in the view, you should use set() in the controller:

$this->set(
'level',
$this->TopicTree->getLevel($id)
);

This creates a variable that View can access as $level.

Tip: if you have debug set to 1 or 2 (avoid 3 as it creates far too
much info and is best left for serious debugging problems) you can do
this in a model, controller, or view:

die(debug($some_var));

On Thu, Aug 2, 2012 at 11:56 AM, kevin.ncbible <kevin@ncbible.com> wrote:
> Tarique: Thank you, so much.
>
> Yes, this is just being used by the one model. (If it was being used by
> more, then where would I put it?)
>
> So, per your instruction, I placed $this->TopicTree->getLevel($id); in one
> of my controller functions and successfully call it from a view. It in turn
> successfully passes the id and calls the function (confirmed by debug) I
> have in my model. But the function, when places in the model, does not
> return any data as it did when it was placed in the controller. What am I
> missing? I'm very new, so it will be very obvious!
>
> Here, as above, is the function, in TopicTree model, I'm successfully
> calling from my controller.
>
> public function getlevel($id=null) {
> $count = count($this->TopicTree->getPath($id,array('TopicTree.id')))-1;
> return $count;
> }
>
> Is the problem that the function, now that it is in the model and not the
> controller, does not know which data to access?
>
> I do, so very much, appreciate your help.
>
> Kevin
>
> --
> 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+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php

--
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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate