Symfony output only template--without adding to layout.php - php

Is there any way to disable the addition of layout.php to my actionNameSuccess.php? I would like this setting to be enabled for some modules and disabled(i.e. let layout.php add up) for other modules.
I can solve the problem by making a new application and setting its layout.php to just
<?php echo $sf_content?>
but I would like a same-application solution. Since I need to have links between these two and link_to only works relative to an application and I don't want to pass an absolute url.

You can call $this->setLayout(false); in your action. I think you may also achieve this with the view.yml file.
UPDATE: as denys281 pointed out, the way to do this in view.yml is to use
has_layout: false

Related

CodeIgniter paths messing up CSS background-image directive

So, I am working on a website with backend for two customers. Both will have different URLs. I had a problem with Javascript links (ajax calls using url:) but that was solved using a global :
var SiteURL='<?php echo base_url();?>';
and append it to calls as necessary. The problem is when my paths go deeper e.g. website.com/book/sheet/2
the relative links would continue from 2/
While I am done with the JS, I am really lost on the CSS. I don't want to give absolute path, e.g. for background-image:url() as it will change with new customers.
Any way I can make use of base_url() or any other function?
#DFriend: that somehow failed for mine as it looked for images folder in css...Firebug showed "http://localhost/samplestud/assets/css/images/listicons/arrow_double.png"
Simple "../images" seems to have fixed it pretty well. Thanks fellas.

Absolute paths in CakePHP project

i was given a pretty big cakePHP (built on v. 1.3.10) project to maintain. The problem is that the majority of the paths are absolute (which on my opinion is a bad habit).
Eg. in default.ctp there is:
<link rel="stylesheet" href="/css/public_new.css" />
but then at the bottom of the same file there is:
<?php echo $html->script('jquery-ui-1.8.16.custom.min.js'); ?>
which prints the correct paths.
It's like the original developers made the site to put in a server's root (not in a subdirectory).
Things ive tried to solve this problem without success:
modified the .htaccess files on /, app/, and app/webroot
adding a tag
I know i can add a $this->base to the beginning of every path, but this is not a solution since there are thousands of files to modifiy :(
So my question: is there any solution using mod_rewrite or such?
Thanks in advance.
$html->script() will automatically prepend /js/ in the HTML output. Cake's .htaccess will then point these file calls to /webroot/js/.
So <?php echo $html->script('jquery-ui-1.8.16.custom.min.js'); ?> would output
/js/jquery-ui-1.8.16.custom.min.js in the HTML.
To replace all those urls / links you could actually use a program like Actual Search and Replace ;-) I use it a lot.
Solution:
on app/config/boostrap.php, add:
Configure::write('App.base', '/teka_new/');
I take this out from Ho do I change the base path of routes in CakePHP?

how to add stylesheet to my layout and pass values from view to layout

I am using zend framework.
My structure is (only included files and folders needed for this question):
application
>configs
>controllers
>forms
>images
>layouts
>scripts
>layout.phtml
>models
>styles
>style.css
>views
>scripts
>index
>index.phtml
Bootstrap.php
docs
library
logs
public
test
I have got the layout working properly. However, I want to ask a couple of questions in order to get my set up perfect for the way I want it.
Is application>styles a good place for the stylesheet to be? If not what's the recommended?
How do i add the stylesheet to the layout?
In my layout I have a title tag : <title>Text</title>. How do I pass values from my controllers to it?
Stylesheets need to be accessible from the browser, so typically you will put these somewhere in the public directory, such as public/css
There are several ways, including placing rel tags in your view/layout, but my preferred option is to use the viewHelper within your controller:
$this->view->headLink()->setStylesheet('/css/style.css');
Then your call to headLink() in the layout file will automatically include the stylesheet.
The way I have done this is to use the Zend_Registry in the past. There may be better ways.

zend-framework problem using routes

UPDATE:
Turns out it's not only the routing, but any instance of going 'up' a directory.
For example mysite.com/public serves me the correct index.phtml file...
mysite.com/index/testpage DOES serve me the testpage.phtml, but my directory structure is completely screwed and I lose all links to images & Stylesheets etc. I've checked my .htaccess and it's exactly as recommended.
Serious head-scratching time here...
OP:
Hello..
I'm using this method for catching urls and serving up the correct content
$router->addRoute(
'list',
new Zend_Controller_Router_Route('/list', array('controller'=>'index', 'action'=> 'list'))
);
And it works really well, serves up the content from list.phtml...
but, the moment I attempt anything 'up' a directory such as this I lose all my style sheets and other relative scripts.
$router->addRoute(
'listWithUsers',
new Zend_Controller_Router_Route('/list/:users', array('controller'=>'index', 'action'=> 'list'))
);
It's strange because I can access the users variable and echo it to screen, it's just that I lose all scripts and stylesheets whenever a URL contains /
For clarity, I'm able to set actions in the indexController.php to catch URLS and it works, but it seems to serve it as another directory causing me to lose all relative links.
Thanks for any help. Please advise if any specific details would help.
For any kind of MVC app using routes like this, you have to specify absolute path for your resources. This will prevent the issue you have.
For example, if I have a website located at mysite.com/app1 and I have a resource located in lib/jquery-1.2.6.min.js, then a valid path will be /app1/lib/jquery-1.2.6.min.js.
For this I have always used some kind of helper to return the site's base URL in my views.
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/lib/jquery-1.2.6.min.js"></script>
You can use a view helper or a constant.

How to switch layout files in Zend Framework?

I'm sure it's a simple one-liner, but I can't seem to find it.
How can I use a different layout file for a particular action?
Update: This worked for me, thanks!
// Within controller
$this->_helper->_layout->setLayout('other-layout') //other-layout.phtml
//Within view script
<?php $this->layout()->setLayout('other-layout'); ?>
From inside a Controller:
$this->_helper->layout->setLayout('/path/to/your/layout_script');
(via these docs)
EDIT: I should mention that the path is relative to whatever your layout directory is (by default, it's application/layouts/scripts/)
You can also use like this
// Within controller
Zend_Layout::getMvcInstance()->setLayout('layout_name');
//Within view script
<?php $this->layout()->setLayout('layout_name'); ?>
Your layout must be in /layouts/scripts/ folder, otherwise you need to specify the path also. No need to write .phtml, just name of the layout

Categories