Re: Proper MVC location for a function and its call

2012-08-03 Thread lowpass
On Fri, Aug 3, 2012 at 9:22 AM, kevin.ncbible  wrote:
>
> A. That was it. So, it makes sense doesn't it, that when you're in the
> model you do not need to reference the model, so  $this->getPath(...)  is
> enough. So, in MVC terminology, I'm using the model to retrieve the data.

Yes, that's right. In any class, $this refers to the instantiated object.

> re: Set, although I had read about it, I also was not getting the
> significance of set to the MVC pattern. I assume that is the main reason,
> for instance, that I would not be calling a function FROM the view: it's
> more like the Model and Controller are pushing (I'm sure there's a better
> word) the data to the view.

Yes, that's a very good way of putting it. The set() method makes
variables available to the View object. More specifically, it add the
var to the controller's $viewVars array, which Cake makes available to
View.

> Now, in my case, the $id value for a particular topic is available in the
> view or edit action, but not in the index or add action. So you've really
> helped me with making the "level" variable available to the view or edit
> action. What if, however, for the index page, I had the $id available, but
> only via a request param. Would that be a case where set would not work and
> I would have to somehow call the getLevel function right from the view?
> A. I guess I do have $id available, in the index action, via $id =
> $this->request->params['named']['id']; Then I could go ahead and use
> $this->set('level', $this->TopicTree->getLevel($id)); Does that make sense?
> I'll have to try that!

Tentatively, yes. I couldn't say for sure without knowing more about
what you're doing.

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


Re: Proper MVC location for a function and its call

2012-08-03 Thread kevin.ncbible
cricket:

A. That was it. So, it makes sense doesn't it, that when you're in the 
model you do not need to reference the model, so  $this->getPath(...)  is 
enough. So, in MVC terminology, I'm using the model to retrieve the data.

re: Set, although I had read about it, I also was not getting the 
significance of set to the MVC pattern. I assume that is the main reason, 
for instance, that I would not be calling a function FROM the view: it's 
more like the Model and Controller are pushing (I'm sure there's a better 
word) the data to the view. 

Now, in my case, the $id value for a particular topic is available in the 
view or edit action, but not in the index or add action. So you've really 
helped me with making the "level" variable available to the view or edit 
action. What if, however, for the index page, I had the $id available, but 
only via a request param. Would that be a case where set would not work and 
I would have to somehow call the getLevel function right from the view? 
A. I guess I do have $id available, in the index action, via $id = 
$this->request->params['named']['id']; Then I could go ahead and 
use $this->set('level', $this->TopicTree->getLevel($id)); Does that make 
sense? I'll have to try that!

As you can see, I'm trying to get my head around MVC patterns, how they 
play out on the practical level. Thank you, cricket and others, so very 
much, for helping me to do this!

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


Re: Proper MVC location for a function and its call

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


Re: Proper MVC location for a function and its call

2012-08-02 Thread kevin.ncbible
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Proper MVC location for a function and its call

2012-08-01 Thread Dr. Tarique Sani
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  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+unsubscr...@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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Proper MVC location for a function and its call

2012-08-01 Thread kevin.ncbible
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php