I feel my problem is relatively simple. I'm new to the Zend framework and I'd like to be able to call a controller to do some work for a header or a footer. I've already created a HeaderController and a applications/views/scripts/headers/index.phtml - all I'm trying to do is get that data, and put it in my layout by default.
Everything works if I navigate to /header, by the by.
Edit:
Made some progress - if I add:
$this->render("header/index.phtml");
it renders all the static data, but doesn't seem to be running the HeaderController.
Try this bit of code out, be sure to disable the layout in your header controller, as the purpose is only to render a limited amount of content.
<?= $this->action('index', 'header', null, array('possible_args'=>'here')); ?>
The documentation can be seen here.
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.action
Related
I have a Wordpress website. I am asking for help as I am not good with codes, but know a bit about the flow of functions and all.
I want to add a new PHP function that will be defined in a separate file. The function to be defined is required to serve a 728x90 banner ad on top of the header area of the site (so I guess the php function will also have CSS styling to align the ad in the center). I don't know what I am saying will be possible the way I am saying.
Alternatively, there might be a way to call a js function defined in separate file, then called in the php header to serve the banner (again center-aligned).
I am seeking help here as Stackoverflow also helped me solve problems previously.
Is there anyone who can help me get this thing done?
Once you have your PHP handler written in a separate file call it using require_once like this:
<?php
require_once('myfile.php');
// Wordpress Stuff
?>
I guess PHP have no relation with CSS/styling, you can do it with Javascript.
like this or using JQuery
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.
I tried force refresh on my browser and change the name of the layout from main.php to main_.php still nothing happened. No visible effect, no error, no nothing.
I'm sure missing a small detail here. Can anyone guide a beginner in this problem?
Version: Yii 1.1.10
check the main layout in site/layouts and in themes/layouts too, definitely there are more version of it.
For you the yii debug toolbar 3rd party extension would definitely help to identify the layout file that is used, install it.
You can control which layout files is included with the controller's $layout property
You need to tell your controller to use layouts from the current module, with single slash notation eg : $layout = '/site/myview' read more about this at: getLayoutFile()
I have a quick question here. Let say I have a view file myView.ctp in cakePHP and inside my view I have some javascript (which I have there for a reason). I know I can tell cake to put my javascript code into the header section of my page by using the scriptStart() and scriptEnd() blocks like:
<?php $html->scriptStart(array('inline' => false)); ?>
// My script code goes here...
<?php $html->scriptEnd(); ?>
The array('inline' => false) is what actually tells cake to put my script in the header. Now my question is this: How do I achieve the same thing for css codes (WITHOUT putting my css codes into an external file)? This techniques seem to only work for javascript codes.
Thank you
Ran into this article when I was looking to do the same thing. Turns out there is now (as of Cake 2.1) a slightly more modern way of accomplishing this using view blocks. To wit:
$styleTag = $this->Html->tag('style', $yourCSS);
// adds your stuff to the "css" block which is injected via "fetch" in
// the head section from the view's layout
$this->append('css', $styleTag);
P.S. Would be nice if there was a HtmlHelper::tag() equivalent for style blocks instead of merely the content, just for cleanliness. Oh well.
$css = $this->Html->tag('style', '/* my css */');
$view =& ClassRegistry::getObject('view');
$view->addScript($css);
The addScript() function on the view will append your script to the $scripts_for_layout var.
Edit: Comment reiterated something important I missed so I revised the answer.
I have a self-made math captcha and it should be output without anything before it's image header, so I can't make it a 'View'. I put this captcha.php in the web root dir, but it can't share session with scripts in Yii. How to solve this?
Is there any way to pass the session from Yii to the other scripts or clean anything before the header in view?
Though it is true that the default layout wraps the page's content with the typical html markup you'd expect, you have complete control over that by specifying the layout you'd like from the controller by using $this->layout = ... You can set it to null to use module layout or false to disable the layout completely. See more details in Yii API Docs.
Alternatively you can call $this->renderPartial('view name') if you'd like the output of your captcha script displayed without the surrounding page content.