Social Engine 4 User profile rerouting - php

For Social Engine 4, which uses Zend framework.
I want to show user profiles under subdomains. so, http://domain.com/profile/username will be http://username.domain.com
How can I do this. I do already have one extension which makes http://domain.com/profile/username to http://domain.com/username Here is the code for it.
$route = array(
'user_profile' => array(
'route' => ':id/*',
'defaults' => array(
'module' => 'user',
'controller' => 'profile',
'action' => 'index'
),
'reqs' => array(
'id' => "\b.+"
)
)
);
Zend_Registry::get('Zend_Controller_Front')->getRouter()->addConfig(new Zend_Config($route));
Is it possible to change it to work for subdomains? If yes how can I do it?
Thank You in advance.

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
':id.'.$setting['siteurl'],
array(
'module' => 'user',
'controller' => 'profile',
'action' => 'index',
)
);
$plainPathRoute = new Zend_Controller_Router_Route_Static('');
$router->addRoute('user_profile', $hostnameRoute->chain($plainPathRoute));

Related

Render header with /abc/abc/abc php

I have experience with php but i'm new to the zend frameworks. Could some one please give me some leads as to how I can get a site to work ie- www.facebook.com/nathandoe/photos
.
Using controllers how can i create a function that accepts different names and direct it that page ?
if i have a site www.hello.com/profile
instead of using GET www.hello.com/profile?is=342342?photos
how to handle it as www.hello.com/profile/342342/photos
i have controllers that handle the index and i know how to create different functions .. im stuck with www.hello.com/profile/xxxxxxxx/photos that part
In your module/[Module Name]/config/module.config.php, you can set the routes.
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
Something like
'route' => '/profile/[/:id]/photos',
Reference http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html

Using route in Zend Framework 2

i need to route urls like in zf1.
in particular i need that these urls will be automatically redirect to appropriate actions without specify a new route every time.
/site/getData
/site/getData?param=5&par2=test
/site/getOther
...
So a segment route doesn't work, i've tried a Literal route but i can't reach a working solutions.
Anyone can help me?
Thanks a lot
This should be solved by a pretty default segment route like the one provided in the documentation.
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/:controller[/:action]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]+',
'action' => '[a-zA-Z][a-zA-Z0-9_-]+',
),
'defaults' => array(
'controller' => 'default-controller-alias',
'action' => 'index',
),
)
Now if you set up your controller names like the following:
'controllers' => array(
'invokables' => array(
'sites' => 'Namespace\Controller\SitesController',
'other' => 'Namespace\Controller\OtherController'
Then you should be able to achieve exactly what you want. And to create params to your route, you simply use the ViewHelper correctly ;)
$this->url('routename',
array(
'controller' => 'site',
'action' => 'getData'
),
array (
'query' => array(
'param1' => 'foo',
'param2' => 'bar',
'paramN' => 'baz',
)
)
)

ZendFramework 2 - How to make all the actions available with one router rule? Its only allowing action index

How to allow all sub actions inside that controller with one router rule? For example this follow:
visit: site/login - works only
site/login/forgetpassword - does not work
site/login/remmeberme - does not work
Example:
$router = $e->getApplication()->getServiceManager()->get('router');
$route = Http\Literal::factory(array(
'route' => '/login',
'defaults' => array(
'controller' => 'Application\Controller\Login',
'action' => 'index'
),
));
$router->addRoute('login', $route, null);
Follow up:
How can i make it so that /login and /login/anything works?
$route = Http\Segment::factory(array(
'route' => '/login[/:action]',
'defaults' => array(
'controller' => 'Application\Controller\Login',
'action' => 'index'
),
));
$router->addRoute('login', $route, null);
There is an excellent QuickStart Tutorial available within the official Documentation. Set up your route like the following to be allowed multiple actions and an ID Parameter. Fur further information please take a look at the documentation.
You may also be interested in DASPRiDs presentation from ZendCon2012
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),

Add Zend_Controller_Router_Route replaced default route

When I added this route
$classes_router = new Zend_Controller_Router_Route(
'/:filter1/:filter2/*',
array(
'module' => 'course',
'controller' => $filter_controller,
'action' => 'index',
'filter1' => '',
'filter2' => ''
)
);
Te default route :module/:controller/:action doesn't work anymore. Please tell me what is the problem?
The problem is that a request to somemodule/somecontroller/someaction will be matched by the route you've added (which will be checked before the default one). You need to provide some restriction in the route to determine what it matches, perhaps by limiting the possible matches for the :filter1 variable:
$classes_router = new Zend_Controller_Router_Route(
'/:filter1/:filter2/*',
array(
'module' => 'course',
'controller' => $filter_controller,
'action' => 'index',
'filter1' => '',
'filter2' => ''
), array(
'filter1' => '(value1|foo|somethingelse)'
)
);
or adding a static prefix:
$classes_router = new Zend_Controller_Router_Route(
'/filter/:filter1/:filter2/*',
array(
'module' => 'course',
'controller' => $filter_controller,
'action' => 'index',
'filter1' => '',
'filter2' => ''
)
);

How to redirect requests to www.example.com/admin to different module in Zend

I have a problem with redirecting requests in my application.
My rules:
employer.domain.com - should point to a page of the employer - uses default module
employer.domain.com/panel/ - should point to a administration page of specific employer - uses dashboard module
www.domain.com - should point to page aggregating all employers - uses default module
I've tested a lot of different routes, but when one route is working, other get broken. Also often it works only for root paths, but when I add call to some controller and action - it crashes. Maybe I should write custom controller plugin? What do You think?
Here is my current configuration. It's a mess, but maybe it will help catching some silly mistake.
// employer.domain.com/panel
$pathRoute_panel = new Zend_Controller_Router_Route(
':panel/:controller/:action/:id/',
array(
'panel' => '',
'module' => 'dashboard',
'controller' => 'index',
'action' => 'index',
'id' => '',
),
array(
'panel' => 'panel'
)
);
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
':employer.'.$config['host'],
null,
array(
'employer' => '([a-z0-9]+)',
)
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));
// employer.domain.com - main employer page
$pathRoute_panel = new Zend_Controller_Router_Route(
'',
array(
'module' => 'default',
'controller' => 'vcard',
'action' => 'index',
'id' => '',
)
);
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
':employer.'.$config['host'],
null,
array(
'employer' => '([a-z0-9]+)',
)
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));
// domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
array(
'module' => 'default',
'controller' => 'index',
'action' => 'index',
),
$dispatcher,
$request
);
$route = new Zend_Controller_Router_Route_Hostname($config['host']);
$router->addRoute('default', $route->chain($pathRoute));
// www.domain.com/
$pathRoute = new Zend_Controller_Router_Route_Module(
array(
'module' => 'default',
'controller' => 'index',
'action' => 'index',
),
$dispatcher,
$request
);
$route = new Zend_Controller_Router_Route_Hostname('www.'.$config['host']);
$router->addRoute('default_www', $route->chain($pathRoute));
EDIT: This is my solution:
// employer.domain.com
$pathRoute_panel = new Zend_Controller_Router_Route_Module(
array(
'module' => 'default',
'controller' => 'vcard',
'action' => 'index',
'id' => '',
)
);
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
':employer.'.$config['host'],
null,
array(
'employer' => '([a-z0-9]+)',
)
);
$router->addRoute('employer_vcard', $subdomainRoute->chain($pathRoute_panel));
// employer.domain.com/panel/
$pathRoute_panel = new Zend_Controller_Router_Route(
'panel/:controller/:action/:id/',
array(
'panel' => 'panel',
'module' => 'dashboard',
'controller' => 'index',
'action' => 'index',
'id' => '',
)
);
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
':employer.'.$config['host'],
null,
array(
'employer' => '([a-z0-9]+)',
)
);
$router->addRoute('employer_panel', $subdomainRoute->chain($pathRoute_panel));
// Enforce Subdomain usage
// Will match employer.domain.com/*
$subdomainRoute = new Zend_Controller_Router_Route_Hostname(
'employer.'.$config['host'] . '/*'
);
// Will match /panel/{id, required}/{controller, optional}/{action, optional}/{further parameters, optional}
$pathRoute_panel = new Zend_Controller_Router_Route(
'panel/:id/:controller/:action/*',
array(
'module' => 'dashboard',
'controller' => 'index',
'action' => 'index'
),
array(
'id' => '\d+'
)
);
// employer.domain.com - main employer page
// will match everything not matched before!
$pathRoute_page = new Zend_Controller_Router_Route(
'*',
array(
'module' => 'default',
'controller' => 'vcard',
'action' => 'index'
)
);
// You can add several routes to one chain ;) The order does matter.
$subDomainRoute->chain($pathRoute_page);
$subDomainRoute->chain($pathRoute_panel);
$router->addRoute($subDomainRoute);
Annotations are in the code. You can use the wildcard (*) to match anything further! There's no need of the default_www route - this's just the default behaviour (the default route now will match every subdomain but employer as it is matched by the subDomainRoute).

Categories