Will this function be used by just one model - TopicTree? ? If yes
then put it in model and call it from the controller
$this->TopicTree->getLevel($id);
HTH
Tarique
On Thu, Aug 2, 2012 at 8:22 AM, kevin.ncbible <kevin@ncbible.com> wrote:
> Hello. Thank you, so very much, for you time and expertise.
>
> I am just getting started with PHP, MVC, and CakePHP. Having read through
> the documentation, I'm still confused about how, where to do things with
> proper MVC. I have a function for a TreeBehavior that returns the level of a
> node in the tree (1, 2, 3, etc.) based upon getPath() method.
>
> /**
> * getlevel
> *
> * @param int $id
> * @return int
> */
> public function getlevel($id=null) {
> // Count of array items, minus one, will tell me the level of the node
> $count = count($this->TopicTree->getPath($id,array('TopicTree.id')))-1;
> // debugger::dump($count); die;
> return $count;
> }
>
> The function works with debugger::dump($count); die;, producing a result,
> e.g.: (int) 4
>
> Now, I would like to use that returned value in the controller's edit and
> add actions, to insert into the database this value in a "level" field.
>
> I want to use proper MVC approach. So, where does this function reside (in
> the TopicTree Model?) and where do I call it (from the edit and add actions
> of the TopicTreesController?) ?
>
> Maybe this is an entirely different issue, but would your answer change if I
> also wanted to use the function to, say, include the level in the Title of
> the index view?
>
> So confused, but really do want to learn how to do this right!
>
> Thank you!!
>
> 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
--
=============================================================
PHP for E-Biz: http://sanisoft.com
=============================================================
--
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
Wednesday, August 1, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment