RIRedinPA Posted July 9, 2010 Share Posted July 9, 2010 I'm new to Cake (and using frameworks in general). I think I am having a syntax issue here. What I am trying to do is pass a value back to the function and then load a page based on the value passed: Here's my controller: <?php class BlogpostsController extends AppController { var $name = "Blogposts"; var $scaffold; function index() { $this->set('posts',$this->Blogpost->find('all')); } function viewuser($userid) { $this->set('thisuser', $this->User->find($userid)); } } ?> In my cpt file I have this: <td class="user"><?=$html->link($post['User']['name'], 'viewuser');?></td> I know this won't work because I am not passing anything to viewuser, I get this error message: Warning (2) <javascript:void(0);> : Missing argument 1 for viewuser() [APP/controllers/blogposts_controller.php, line 13] Which is good, in a way. But if I rewrite it like this: <td class="user"><?=$html->link($post['User']['name'], 'viewuser("1")');?></td> I get another error: Missing Method in BlogpostsController Error: The action viewuser("1") is not defined in controller BlogpostsController Which seems to be telling me I am not writing the syntax for passing values correctly... Link to comment https://forums.phpfreaks.com/topic/207273-cake-passing-values-to-a-function/ Share on other sites More sharing options...
pornophobic Posted July 10, 2010 Share Posted July 10, 2010 This is happening because you probably haven't called the class as an object. You'll need to call the class as an object first. $bpControl = new BlogpostsController(); and then call the function within the class by doing something like this: $userGet = $bpControl->viewuser("1"); That should solve the "method" error and all that. If you want to understand more about Objects, Classes and all that I provided a link, but here it is again: http://php.net/manual/en/language.oop5.php Link to comment https://forums.phpfreaks.com/topic/207273-cake-passing-values-to-a-function/#findComment-1084211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.