This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Call to undefined method sfRoute::getObject() affiliate

Discussion around this tutorial for symfony 1.2-1.4

Call to undefined method sfRoute::getObject() affiliate

by scvroin » Sat Dec 11, 2010 8:05 pm

Hello,

I don't know what I broke, but on my localhost system in the backend when I try to activete an affilate I got this fatal error:
Fatal error: Call to undefined method sfRoute::getObject() in /home/silviu/sfprojects/jobeet/apps/backend/modules/affiliate/actions/actions.class.php on line 16

On the same online jobbet, this feature it works.
symfony 1.4.5
php 5.3.3
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Mon Dec 13, 2010 2:57 pm

Well I look in the log and my problem is that
Match route "default" (/:module/:action/*) for /affiliate/ListActivate/id/3
instead of the route: jobeet_affiliate.
How can I reorder the routes? Also from the log I see that first it takes the routes for the sfDoctrineGuardPlugin and after that it matches with the default route.
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by halfer » Mon Dec 13, 2010 3:37 pm

Make sure the route you want to match is above the default route in routing.yml - this file is scanned in order, and the scanning stops when a match is found.
halfer
Faithful Member
 
Posts: 10148
Joined: Mon Jan 30, 2006 1:16 pm
Location: West Midlands, UK

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Mon Dec 13, 2010 6:08 pm

In the routing.yml the order is ok, but when I look in the navigator window of my netbeans, the order is reverse. And in the routing.yml it seams that jobeet_affliate is not ending properly. Here it is my routing.yml:
Code: Select all
# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/10-Routing

# default rules
jobeet_affiliate:
  class: sfDoctrineRouteCollection
  options:
    model: JobeetAffiliate
    module: affiliate
    prefix_path: /affliate
    column: id
    with_wild_cards: true
 
jobeet_category:
  class: sfDoctrineRouteCollection
  options:
    model:                JobeetCategory
    module:               category
    prefix_path:          /category
    column:               id
    with_wildcard_routes: true

jobeet_job:
  class: sfDoctrineRouteCollection
  options:
    model:                JobeetJob
    module:               job
    prefix_path:          /job
    column:               id
    with_wildcard_routes: true

homepage:
  url:   /
  param: { module: job, action: index }
# generic rules
# please, remove them by adding more specific rules
default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*


Ps: When I tried to fix this, more precisely to write again the first routes: jobeet_affliate and the next, after I have made a new build and load, I broke also the the route: affliate
404 | Not Found | sfError404Exception
Action "affliate/index" does not exist.
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by Vicrabb » Tue Dec 14, 2010 10:25 am

scvroin wrote:
Code: Select all

# default rules
jobeet_affiliate:
  class: sfDoctrineRouteCollection
  options:
    model: JobeetAffiliate
    module: affiliate
    prefix_path: /affliate
    column: id
    with_wild_cards: true




Just a question, is it normal that your prefix_path is affliate instead of affiliate? I don't say it will solve your problem though
Netbeans 6.9- Mysql Workbench 5.2
Symfony 1.4.8
Wamp server 2.0 (=>PHP 5.3.0, Apache 2.2.11, Mysql 5.1.36, phpMyAdmin)
Windows XP/7 (depending on where I am)
Firefox 3.6 - Chrome (some IE8, rarely Opera and Safari, testing Rockmelt at home)
Vicrabb
Junior Member
 
Posts: 13
Joined: Mon Nov 22, 2010 1:10 pm
Location: Belgium

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Tue Dec 14, 2010 3:34 pm

Yes, it was a mistake there, thank you. But now I can't access the link to the affiliates http://www.jobeet.com.localhost:8080/ba ... /affiliate, because of this error:
500 | Internal Server Error | sfConfigurationException
The route "jobeet_affiliate_collection" does not exist.

if I look at the routes in the backend, with app:routes, indeed there's no route jobeet_affiliate_colection but there are two routes:jobeet_category_collection and jobeet_job_collection, and I don't know from where these 2 comes.
Here it is my routing.yml:
Code: Select all
# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/10-Routing

# default rules
jobeet_affiliate:
  class: sfDoctrineRouteCollection
  options:
    model:               JobeetAffiliate
    module:              affiliate
    prefix_path:         affiliate
    column:              id
    with_wild_cards:     true
 
jobeet_category:
  class: sfDoctrineRouteCollection
  options:
    model:                JobeetCategory
    module:               category
    prefix_path:          category
    column:               id
    with_wildcard_routes: true

jobeet_job:
  class: sfDoctrineRouteCollection
  options:
    model:                JobeetJob
    module:               job
    prefix_path:          job
    column:               id
    with_wildcard_routes: true

homepage:
  url:   /
  param: { module: job, action: index }
# generic rules
# please, remove them by adding more specific rules
default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*


And in the layout.php if have like this for the link affiliates:
Code: Select all
 <li>
              <a href="<?php echo url_for('@jobeet_affiliate') ?>">
                Affiliates - <strong><?php echo Doctrine::getTable('JobeetAffiliate')->countToBeActivated() ?></strong>
              </a>
            </li>
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Tue Dec 14, 2010 6:28 pm

I recreate again the routing.yml, again, and this time it's ok. But still I got one difference: in my online( the same jobeet, well almost) the route that is execute when the user( me) click on the affliates link is jobeet_affiliate but on my localhost the route is default_index.
What I wanted to try, on my localhost system, was sending the mail when an affiliate was activated in the backend. This works just fine in the online version. But now, I have another problem: I don't know why my frontend from my local system, ends'up with a blank page?
I look both in the frontend_dev.log and in the error_log of the appache and I don't see no reason why the frontend application ends up with a blank page.
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Wed Dec 15, 2010 11:33 am

It was a mistake in my frontend controller and this way my frontend application doesn't start, but now this is fixed.
Problem is that I have return where I started:
Call to undefined method sfRoute::getObject()

I look back on both my jobeet project, local and online, on the backend application and I see a major difference.
The difference is the link in my browser when I want to activate an affiliate, so here it is:
1. in my local I have like this: /affiliate/ListActivate/id/3
2 on the online is like this:affiliate/469/ListActivate

I wonder if this would have something with my error?
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by claudia_k » Sun Dec 19, 2010 8:03 pm

Yes, most likely this has something to do with your error. Apparently your routing goes wrong somehow - not sure why though.
Because of the wrong routing your route is matched to the default route which is of type sfRoute, not sfDoctrineRouteCollection (like the jobeet_affiliate route). Since sfRoute does not have a method getObject() you get the error message.

I don't know why the routing goes wrong, so could you please post both the routing.yml of your backend (the way to looks now) and the generator.yml of your backend affiliate module here?


Claudia
claudia_k
Faithful Member
 
Posts: 265
Joined: Mon Jun 21, 2010 8:12 pm
Location: Luxembourg

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Mon Dec 20, 2010 3:45 pm

Sure, here it is, routing.yml from the backend:
Code: Select all
jobeet_affiliate:
  class: sfDoctrineRouteCollection
  options:
    model:               JobeetAffiliate
    module:              affiliate
    prefix_path:         affiliate
    column:              id
    with_wildcard_routes: true

jobeet_category:
  class: sfDoctrineRouteCollection
  options:
    model:               JobeetCategory
    module:              category
    prefix_path:         category
    column:              id
    with_wildcard_routes: true

jobeet_job:
  class: sfDoctrineRouteCollection
  options:
    model:               JobeetJob
    module:              job
    prefix_path:         job
    column:              id
    with_wildcard_routes: true

# default rules
homepage:
  url:   /
  param: { module: job, action: index }

default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*

and the generator.yml from affiliate module:
Code: Select all
generator:
  class: sfDoctrineGenerator
  param:
    model_class:           JobeetAffiliate
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          jobeet_affiliate
    with_doctrine_route:     1

    config:
      actions: ~
      fields:
        is_active: { label: Active }
      list:
        title:   Affiliate Management
        display: [is_active, url, email, token]
        sort:    [is_active]
        object_actions:
          activate:   ~
          deactivate: ~
        batch_actions:
          activate:   ~
          deactivate: ~
        actions: {}
      filter:
        display: [url, email, is_active]
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Tue Dec 21, 2010 4:27 pm

Hello,

With the help of the Kompare, I look into the difference of the two projects, and now the local project is working as the online does, but only after I apply the difference existing in the file config_routing.yml.php from the cache folder, $this->routes['default_index'] and $this->routes['default'] being the last ones, and not after the $this->routes['homepage'].
Now the link to activate an affiliate is like this: affiliate/3/ListActivate .
I still have 2 question before consider this post solved:
1. Why was that difference in config_routing.yml.php, because the routing.yml was the same.
2 Is this link correct: affiliate/3/ListActivate? How is it in your jobeet backend?

Thank you.
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by claudia_k » Tue Dec 21, 2010 9:28 pm

Sorry for the late reply...

My routing.yml looks a bit different from yours - the prefix path in each block starts with a forward slash and I do have a homepage route which comes directly after the jobeet_affiliate block. But my backend still works fine if I use your routing.yml (and clear the cache afterwards), so these differences apparently do not account for the problem that you have. Same for generator.yml.

So I do not know where your problem could come from, sorry.

I am not sure whether fixing the config_routing.yml.php will really solve your problem - AFAIK this file is deleted each time you clear the cache.

Is this link correct: affiliate/3/ListActivate? How is it in your jobeet backend?
The same - this link looks like the ones in my backend.


Claudia
claudia_k
Faithful Member
 
Posts: 265
Joined: Mon Jun 21, 2010 8:12 pm
Location: Luxembourg

Re: Call to undefined method sfRoute::getObject() affiliate

by scvroin » Wed Dec 22, 2010 10:46 am

Thank you, Claudia, for your answer. So if it's not the routing.yml or the generator.yml file, then why I have that difference in my config_routing.yml.php? I see it's auto-generated by sfRoutingConfigHandler, but I don't know I why it misplaced the 2 routes: defualt and defualt_index?
Well, till I will find the answer to my question, I could consider this post almost solved, with this workaround.
Thank you, once again.
Silviu
I'm learning symfony.
the php force is strong in me ;)
scvroin
Member
 
Posts: 35
Joined: Mon May 31, 2010 7:06 pm
Location: Craiova, RO

Re: Call to undefined method sfRoute::getObject() affiliate

by wilbert » Tue Aug 28, 2012 10:55 pm

I had this very same problem after finishing Day 20 of the Jobeet tutorial about building plugins. When I checked the routes of the backend, I found out that all the frontend routes preceded the routes from the backend, so it was the default route from the frontend that was "seen" before the jobeet_affiliate route from the backend.

There are two obvious solutions that worked for me:
1] Disable the default route from the frontend routes.
2] Move the routing.yml from the plugin back to the config directory of the frontend.

(Or both, if you like.)
wilbert
Junior Member
 
Posts: 1
Joined: Tue Aug 28, 2012 10:51 pm