I have a plugin to detect mobile view or desktop view. I need to be able to change my view layout based on either the user is view from a mobile device or desktop.
I tried to control the logic in Zend_Controller_Plugin Abstract Class in dispatchLoopStartUp() method and also in the bootstrap method _initLayoutName() but I still couldn't achieve the result.
Find the below snippet of what i expected to achieve
public function checkDetectDevice() {
$detect = new My_MobileDetect();
if($device->isMobile()) {
//Change View Layout.
}
}
Can someone help me on how to achieve view layout changing in Zend v1
To change the layout in a plugin, try this:
Zend_Layout::getMvcInstance()->setLayout('your_layout'); // for your_layout.phtml
Related
Im trying to get the layered navigation of a category links from a php that is outside magento.
I can create all of the category html, but the problem is that the layered links are created with the params of frontcontroller (at the same way of the toolbar links).
If i have a filter selected the creation of layered links doesnt take account of it, and also the layered links havent the category url...
I try to recreate the frontcontroller of the category page inside magento on my php ouside that, but i haven success... Even i recreate the $_SERVER, but the controller seems to not find a router...
In the php if i use mage::run, it do the operation of calcule correctly but mage::run makes the response and isnt i want because i need an xml output only of layered navigation.
If i use mage::app i can get the category html, but the controler isnt calculated correctly although is the same $_SERVER[request_uri] and havent correct links. The front controller havent action...
In the frontcontroller request i see two differences: in magento dispathed is true, but in the php no, and in magento de request_uri are rewrited to catalog/category/view/id/7?color=99 while in the php not hombre.html?color=99
Im missing anything, i need to initialize the front controller? o reinitialize???
Or there a different way to get the layered navigation from outside magento??
I found the problem and the solution...
On start magento it calls to rewrite the URL with the aim to get converted friendly url on a route url...
hombre.html?color=99 is converted on catalog/category/view/id/7?color=99
So the first is to call Mage::getModel('core/url_rewrite')->rewrite(); and now our frontcontroller request have the URL converted correctly.
Before that the frontendcontroller is inited executing the function match in all of its routers to try to find a controller and an action...
$frCont = Mage::app()->getFrontController();
foreach ($frCont->getRouters() as $router) {
if ($router->match($frCont->getRequest())) {
break;
}
}
With that two steps i have the frontcontroller initialized like if i access to the url "hombre.html?color=99" but in fact im on another php in my services folder.
But the match function after initialize the frontcontroller and get the router, action, and route, dispatch the action by default, so it generate all the html output and cannot work with layouts... So i create a local copy of the class Mage_Core_Controller_Varien_Router_Standard and i have updated the function match:
public function match(Zend_Controller_Request_Http $request){
.
.
.
$controllerInstance->dispatch($action);
return true;
}
for this one
public function match(Zend_Controller_Request_Http $request, $dispatchAction = true){
.
.
.
if($dispatchAction==true){
$controllerInstance->dispatch($action);
}
return true;
}
So in my service php i have that code:
Mage::getModel('core/url_rewrite')->rewrite();
$frCont = Mage::app()->getFrontController();
foreach ($frCont->getRouters() as $router) {
if ($router->match($frCont->getRequest(),false)) {
break;
}
}
And i have the frontcontroller initialized and the action,router,params, etc assigned like if i access from the catalog URL but withouth dispatching the action, and then i can write the objects i want with the layout object.
Hope it helps anyone.
I want to create my custom theme in CakePHP. Where can I save my block in CakePHP directory structure that will contain all my menu links? And how can I fetch the file from View\Themed\MyTheme\Layouts\default.ctp?
Either use Elements (if your navbar shows on every single view) or use View Blocks (if navbar only shows on some views).
In your default.ctp file you would just do..
echo $this->element('navbar');
Which would render Views/Elements/navbar.ctp onto Views/Layouts/default.ctp (if you are using the default layout).
To access: View\Themed\MyTheme\Layouts\default.ctp, in (Cake 2.1+), you must tell cake which theme you want to use like so:
public $theme = 'MyTheme';
// or override in an action:
$this->theme = 'MyTheme';
Then:
$this->layout = 'default';
will refer to your View\Themed\MyTheme\Layouts\default.ctp.
If cake can't find the requested view file in MyTheme, it will fallback to app/View to find it.
In this way you can override views in your theme as needed.
So if you place your menu in View/Elements/menu.ctp, all of your themes will be able to access it. if you want to overwrite it for MyTheme, simply create an Elements/menu.ctp within MyTheme.
The process is slightly different with previous versions of cake if I recall.
Just place it under /App/Views/Layouts. If you want to use it everywhere, call it default.ctp, it will automatically be used. Otherwise, give it a different name, and then in the controller do:
public function some_action() {
$this->layout = 'mylayout';
}
This will display some_action using your layout instead of the default.
I have a website which is built on Codeigniter and I want to create some pages with information like terms or privacy, their address should be:
http://domain.com/terms
http://domain.com/privacy
My question is: should I create for each page a controller? In CMS for example, if I add a page it has to create a 'pysical' page on the server (CMS which is built on Codeigniter)?
For static pages like a Privacy Policy or Terms of Service page where they don't really fit under any other controller I usually create a "content" controller that looks something like this:
class Content extends CI_Controller {
public function privacy_policy()
{
$this->load->view('privacy_policy');
}
public function terms_of_service()
{
$this->load->view('terms_of_service');
}
}
Then I add some routes to remove "content" from the URL:
$route['privacy-policy'] = 'content/privacy_policy';
$route['terms-of-service'] = 'content/terms_of_service';
That way you don't need to create a new controller for each page and you can keep your static pages organized in a single spot.
Something I do is make your policy statements as a DL, DT, DD. hide the DD with jquery, show the DD then on a click to the DT. Then have the DD popup as a modal
The entire thing is contained in the footer. No need for anything to do with the controller
How could I prevent mentioned plugin's login form from using default layout? I am aware of this question, but that answer doesnt work for me. For starters, there's no signin module in modules dir, probably plugins handle it in different way, I dont know. Just learning symfony. Thanks in advance :)
For now its not possible to set custom layout for some sfGuardAuth action via custom view.yml.
This is how I did it.
This is my apps/backend/modules/sfGuardAuth/actions/actions.class.php:
<?php
require_once(sfConfig::get('sf_plugins_dir').'/sfDoctrineGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php');
class sfGuardAuthActions extends BasesfGuardAuthActions
{
public function preExecute()
{
$layout = $this->getActionName() == sfConfig::get('sf_login_action') ? 'sfGuardLayout' : $this->getLayout();
$this->setLayout($layout);
}
}
If you just want to set a different layout, you need to add a module (just create it manually) called "sfGuardAuth". Inside the /config/ directory for that, change the layout in the view.yml like for any other module. This is explained in:
http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin/4_0_0
... under section "Customize sfGuardAuth module actions".
However, if you want to "embed" your login form on another existing page, you could turn the login into a component - which means it uses the existing layout of the page it occurs in.
Component action in a custom module:
public function executeSigninLightbox(sfWebRequest $request)
{
$class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin');
$this->form = new $class();
}
... which like all components uses a partial as its view. The partial now has access to $form like a standard login page. The partial for this would be called "_signinLightbox".
Hope that helps.
Can anyone tell me how can I define and use a specific layout for a model (not a template)? I would like to do this for my custom 404 error page.
As Peter Bailey commented above, your layout is a component of the view and has nothing to do with models. Therefore you'd be able to do something like this in the actions module you're using (normally default):
public function executeError404(sfWebRequest $request)
{
$this->setLayout("your_layout_name");
// ...
}
and then in your [APPNAME]/templates directory, create the your_layout_name.php template file as you would with any other template.