I have configured my zend navigation menu like
Config: http://pastebin.com/B212uWKz
public function _initNavigation() {
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$this->bootstrap('view');
$view = $this->getResource('view');
$view->navigation($navigation);
}
Layout
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Zend Navigation Test</title>
</head>
<body>
<?php echo $this->navigation()->menu(); ?>
<hr />
<?php echo $this->navigation()->breadcrumbs(); ?>
<hr />
<?php echo $this->layout()->content; ?>
</body>
</html>
The menu works but not the breadbrumbs. I also tried from here
<?php echo $this->navigation()->breadcrumbs()
->setLinkLast(false)
->setMinDepth(0)
->render(); ?>
Still only the menu works
Maybe they use different containers?
Maybe max depth?
<?php echo $this->navigation()->breadcrumbs()
->setLinkLast(false)
->setMinDepth(0)
->setMaxDepth(500)
->render($this->navigation()->getContainer()); ?>
Looking at your code I think that the problem might be because you use uri tags rather then controller and action tags. For instance instead of:
<home>
<label>Home</label>
<uri>/</uri>
</home>
there should be:
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
</home>
Hope it will work for you.
Related
It would appear that the WordPress theme that I am working with was not optimized to work with open graph tags. I changed this line of code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
to this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" <?php language_attributes(); ?>>
When I run the url through the debugging tool on FB, it sees the proper image for the homepage, but that's about the only progress I get. When attempting to share an article it pulls no description or image at all (I use featured images) and the FB Debugger says "document returned no data" when I check to see what the scraper returned for the site.
I have had issues with OG tags before and have, through trial and error, solved the problem. This is really frustrating me. I've even tried adding three plugins at once that would all populate the tags, and then running the debugger, hoping it would give me the error message saying "multiple og tags." It does not. Did I not add the code in my header the correct way?
I will provide my entire header code just in case anyone needs it.
<?php include( TEMPLATEPATH . '/includes/options.php' ); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/screen.css" type="text/css" />
<!--[if lte IE 7]><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/ie.css" type="text/css" media="screen, projection" /><![endif]-->
<!--[if lte IE 6]><link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/ie6.css" type="text/css" media="screen, projection" />
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/nav.js"></script><![endif]-->
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php if ( $mb_subscribe_feed ) { echo $mb_subscribe_feed; } else { bloginfo('rss2_url'); } ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if (is_singular()) wp_enqueue_script('comment-reply'); ?>
<?php wp_head(); ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.qtip.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.qtip.style.js"></script>
</head>
<body<?php if ($mb_clean == 1) { echo ' class="clean"'; } ?>>
<!-- header -->
<div id="header"<?php if ($mb_clean == 1) { echo ' class="clean"'; } ?>>
<div id="header-inner">
<div id="header-bottom">
<?php if ($mb_logo == 1) { ?>
<div id="logo-custom" style="width:<?php echo $mb_logo_width; ?>px; height:<?php echo $mb_logo_height; ?>px;"><?php bloginfo('name'); ?><span style="background: url('<?php echo $mb_logo_image; ?>') no-repeat 0 0"> </span></div>
<?php } else { ?>
<div id="logo"<?php if ($mb_clean == 1) { echo ' class="clean"'; } ?>><?php bloginfo('name'); ?><span> </span></div>
<?php } ?>
<?php if ( !$mb_leaderboard ) echo''; else { ?>
<div id="ad-leaderboard">
<?php echo $mb_leaderboard; ?>
</div>
<?php } ?>
<!-- nav -->
<div id="nav">
<div id="navlist">
<?php mb_nav(); ?>
</div>
</div>
<!-- /nav -->
<!-- social -->
<div id="social"<?php if ($mb_clean == 1) { echo ' class="clean"'; } ?>>
<ul>
<?php if ($mb_subscribe_email) { ?><li id="social-email">Email Updates</li><?php } ?>
<?php if ($mb_subscribe_feed) { ?><li id="social-feed">RSS Feed</li><?php } else { ?><li id="social-feed">RSS Feed</li><?php } ?>
<?php if ($mb_social_twitter) { ?><li id="social-twitter">Twitter</li><?php } ?>
<?php if ($mb_social_myspace) { ?><li id="social-myspace">MySpace</li><?php } ?>
<?php if ($mb_social_facebook) { ?><li id="social-facebook">Facebook</li><?php } ?>
</ul>
</div>
<!-- /social -->
</div>
</div>
</div>
<!-- /header -->
First off, the DOCTYPE and opening HTML tags should be separate -- not combined like you have them. See here:
https://www.w3schools.com/tags/tag_doctype.asp
Finally, use a plugin like Complete Open Graph to set up the appropriate prefix and Open Graph tags. It's automatic and should solve your problem, unless you want to continue to fight it manually.
https://wordpress.org/plugins/complete-open-graph/
My zend layout and scripts are detecting fine. but when in init function of my IndexController I write $this->view->render("header.phtml") It does not show anything one the screen, whereas when I write echo ($this->view->render("header.phtml"); it displays my header.phtml file. Here is my IndexController
class IndexController extends Zend_Controller_Action
{
public function init()
{
$layout = $this->_helper->layout();
//$this->view = $this->getResource('View');
echo ($this->view->render("header.phtml"));
//echo"<pre>";
//var_dump($this->view);
//var_dump(APPICATION_PATH);
}
public function indexAction()
{
// action body
echo "In default index con";
}
}
Also when Igive my url to/mypath/index It does not display the simple line "I'm in index controller" which I'm just echoing. In my bootstrap here is my Zend_Layout settings.
Zend_Loader::loadClass('Zend_View');
$this->view = new Zend_View();
$this->view->setEncoding('UTF-8');
$this->view->setScriptPath($this->root .'/application/default/views/scripts');
$viewRenderer=new Zend_Controller_Action_Helper_ViewRenderer();
// Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
// $view->setScriptPath($this->root.'/'.$theme.'/views/scripts/');
//$view->setScriptPath($this->root.'/application/default/views/scripts/');
$this->view->addScriptPath($this->root.'/application/admin/views/scripts');
$this->view->addScriptPath($this->root.'/application/business/views/scripts');
// $this->view->setHelperPath($this->root .'/application/default/views/helpers');
$this->layout = Zend_Layout::startMvc(
array(
'layoutPath' => $this->root . '/application/default/views/'.$crt_theme.'/layouts',
'layout' => 'layout'
)
);
$this->registry->set("theme", $crt_theme);
variable $crt_theme is set to 'default'.
Rob' answer is correct although you may need some more information as you appear to be working hard at making this complicated. ZF when used as an MVC has a place to put layouts and defaults for using them.
If you are using the Zend_Tool command line interface start with the commmand: zf enable layout and the tool will add the default directory and a default layout.phtml to your project.
in the application.ini it will add the line:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
and at that path it will add the file layout.phtml
If you need to change the name of the default layout add this line with the name of your script without the .phtml
resources.layout.layout = master
There are as many ways as you can think of to use this file, but here is an example of how I use it.
I like to set my project defaults in my application.ini file so if I need to change anything it's easy.
View Settings
;*************
resources.view[]=
resources.view.charset = "UTF-8"
resources.view.encoding = "UTF-8"
resources.view.doctype = "HTML5"
resources.view.language = "en"
resources.view.contentType = "text/html; charset=UTF-8"
then in my bootstrap I setup the view I want use, I do it here so that if I have multiple layouts (i usually do) it's easy to change css or js files in one place.
protected function _initView() {
//Initialize view
$view = new Zend_View();
$view->addHelperPath('/../library/Application/View/Helper');
$view->doctype(Zend_Registry::get('config')->resources->view->doctype);
$view->headTitle('Our Home');
$view->headMeta()->appendHttpEquiv('Content-Type', Zend_Registry::get(
'config')->resources->view->contentType);
$view->headLink()->setStylesheet('/css/normalize.css');
$view->headLink()->appendStylesheet('/css/blueprint/src/liquid.css');
$view->headLink()->appendStylesheet('/css/blueprint/src/typography.css');
$view->headLink()->appendStylesheet(
'/javascript/mediaelement/build/mediaelementplayer.css');
$view->headLink()->appendStylesheet('/css/main.css');
$view->headLink()->appendStylesheet('/css/nav.css');
$view->headLink()->appendStylesheet('/css/table.css');
//add javascript files
$view->headScript()->setFile('/javascript/mediaelement/build/jquery.js');
$view->headScript()->appendFile('/javascript/modernizr.js');
//add it to the view renderer
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer');
$viewRenderer->setView($view);
//Return it, so that it can be stored by the bootstrap
return $view;
}
Notice all of those headLink(), headScript() and docType() entries, these are where the data is set for placeholders, that will be used in the layout.
Now the layout, the actual content from your other action based scripts will typically be rendered by the placeholder $this->layout()->content
<?php
echo $this->doctype() . "\n";//placeholder
?>
<html>
<head>
<title></title>
<?php echo $this->headMeta() . "\n" ?><!-- displays all meta data passed -->
<?php echo $this->headLink() . "\n" ?><!-- displays all links passed -->
<?php echo $this->headscript(). "\n"?><!-- displays all scripts passed -->
</head>
<body>
<section class="container">
<header class="block">
<hgroup id="header" class ="column span-24">
<h1>Our Home</h1>
</hgroup>
<nav>
<div id="nav" class="column span-24">
<?php echo $this->layout()->nav ?> <!-- Custom Placeholder -->
</div>
</nav>
</header>
<section class="block">
<div id="main" class="column span-18 border">
<div id="flash">
<?php
//flash messenger display location
if (count($this->messages) > 0) {
printf("<h3 id='flash'>%s</h3>", $this->messages[0]);
}
?>
</div>
<?php echo $this->layout()->content; ?><!-- Default placeholder, where views are rendered -->
</div>
<aside id="sidebar" class="column span-4 last">
<?php echo $this->layout()->search ?><!-- Custom placeholder -->
<div id="subNav">
<?php echo $this->layout()->subNav ?> <!-- Custom placeholder -->
</div>
<div id="adminMenu">
<h4>Administration Links</h4>
<?php echo $this->layout()->adminMenu ?> <!-- Custom placeholder -->
</div>
</aside>
</section>
<footer class="block">
<div id="footer" class="column span-24">
<p>Created with Zend Framework. © </p>
</div>
</footer>
</section>
<?php echo $this->inlineScript() ?><!-- placeholder -->
</body>
</html>
Hope this helps!
[Edit]
One more thing, this always seems to be the next question. "How do I change my layout from the default in my controller/action?"
to change the layout from your controller you would typically do it with a preDispatch() method and just pass the name of your new layout to the layout helper.
$this->_helper->layout->setLayout('myOtherLayout');
doing just this will change the layout for every action in the controller. To be more selective you can use a conditional, like:
if ($this->getRequest()->getActionName() == 'player') {
$this->_helper->layout->setLayout('player');//reset layout
//add 2 new headscripts
$this->view->headScript()->appendFile(
'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'
);
$this->view->headScript()->appendFile(
'/javascript/mediaplayer/jwplayer.js'
);
}
render() is working as intended; it returns a string that you should then echo.
It is very unusual to be rendering directly in a controller however. At a minimum, you should be rendering your header and footer from views/scripts/index/index.phtml, though using Zend_Layout would be even better. If you are using Zend_Application, then you can start using Zend_Layout simply by adding:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
to your application/config/application.ini file. You then need to create a application/layouts/scripts/layout.phtml file which could look something like this:
<?php
$this->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$this->headTitle()->setSeparator(' - ');
$this->headTitle('My website');
?>
<!DOCTYPE html>
<html>
<head>
<?php echo $this->headMeta(); ?>
<?php echo $this->headTitle(); ?>
<!-- Other <head> elements and view helpers here -->
</head>
<body>
<div id="content">
<?php echo $this->layout()->content; ?>
</div>
</body>
</html>
I implemented a Zend project
And its working fine
Now i tried to implement a layout,
Step 1
for that i created a 'layout.phtml' in the folder 'application/layouts'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->headTitle(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php $this->layout()->content ;?>
</body>
</html>
step2
Modified the application.ini and added the following line
resources.layout.layoutpath = APPLICATION_PATH "/layouts" under [production]
Step3
Modified the Bootstrap.php, and added the function '_initViewHelpers()'
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_AutoLoader(
array('namespace'=>'','basePath'=>APPLICATION_PATH)
);
return $moduleLoader;
}
function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Zend Framework Tutorial');
}
}
?>
Step4
I took the url in the browser http://localhost/zf_tutorial/public/
It showing the content of layout page but $this->layout()->content is not working (ie index action of index controller)
What is wrong with this code
You need to echo your content.
<?= $this->layout()->content ?> will do what you want!
You need to echo your content. Either you can use
<?= $this->layout()->content ?>
OR
<?php echo $this->layout()->content ?>
I am using symfony 1.4. I would like to ask you for a help with fancy box. How can i make that fancy gallery after click on my image. Please.
Well i tried do something like that:
in apps/fronted/config/viey.yml
javascripts: [jquery-1.4.3.min.js, jquery.fancybox-1.3.4.js]
also put that files in css folder web/js
in apps/fronted/config/templates/layout.php i leave it with no changes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//PL" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<?php include_http_metas() ?>
<?php include_metas() ?>
<?php include_title() ?>
<?php include_stylesheets() ?>
<?php include_javascripts() ?>
</head>
<body>
<div id="container">
<div class="content">
<?php echo $sf_content ?>
</div>
</div>
</body>
in apps/fronted/modules/myshop/templates/homeSuccess.php i wrote
<a id="single_image" href="images/braceles/1.jpg">
<img src="images/braceles/1.jpg" alt=""/></a>
after that i click on image, it redirect me to page with image instead that fancy view :( i don't get it, what is that "single_image" and what do i do wrong?
Please help me, thanks user! :)
I use fansybox like :
In apps/fronted/config/view.yml
javascripts: [jquery-1.6.2.min.js,fancybox/jquery.fancybox-1.3.4.js,fancybox/jquery.easing-1.3.pack.js,fancybox/jquery.mousewheel-3.0.4.pack.js,fancybox/fancyconfig.js]
stylesheets: [fancybox/jquery.fancybox-1.3.4.css]
In my fancyconfig.js
$(document).ready(function(){
$("a#image_fancybox").fancybox({
'titlePosition' : 'over',
'overlayOpacity' : 0.4
});
});
In my apps/fronted/modules/mymod/templates/indexSuccess.php
<a id="image_fancybox" title="<?php echo $project->getDescription()?>" href="<?php echo "/uploads/projects/".$project->getImage() ?>"> <img src="<?php echo "/uploads/projects/thumbnails/thumb_".$project->getImage() ?>" alt="<?php echo $project->getDescription() ?>"/></a>
So, it is work. You can use firebug in firefox , that debug you js code.
I have the following problem, using zend framework, specifically zend_nav to create a reusable menu to be passed in via the layout/layout.phtml page. These are the code fragments in their respective files.
first of in application/configs/navigation.xml,
<configdata>
<nav>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<add>
<label>Add</label>
<controller>post</controller>
<action>add</action>
</add>
<login>
<label>Admin</label>
<controller>login</controller>
<action>login</action>
</login>
</pages>
</nav>
</configdata>
this is then passed into an object in the Bootstrap.php file(only showing that specific method)
protected function __initNavigation(){
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
}
and then finally in the view layout.phtml, the object should return the menu
<!-- application/layouts/scripts/layout.phtml -->
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zend Blog !</title>
<?php echo $this->headLink()->appendStylesheet('/css/global.css')?>
</head>
<body>
<div id="header">
<div id="header-logo">
<b>Blog Me !</b>
</div>
</div>
<div id="menu">
<?php echo $this->navigation()->menu() ?>
</div>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
</body>
</html>
The menu does however not show up when i start up my app in the browser, any ideas as to might have gone wrong, is humbly received.
If you did not name the function __initNavigation with two _ underscores on purpose then you probably expected the code to run automatically. For it to run automatically you need to use a single underscore.
Another possible problem is that _initNavigation runs before _initView as Zend goes through these resources in alphabetical order. But then you need not access $view in this code. You can use the Zend_Registry to store the navigation container:
protected function _initNavigation() {
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
Zend_Registry::set('Zend_Navigation', $container);
}
The Zend_Navigation registry entry will be used by default by any navigation helper when no container is specified.
Well i`m impressed, really quick answers, the problem had several aspects, first of you where both right about using a single underscore sign, thanks a lot the both of you !
And as i t turned out, i did misspell,
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
should be,
$config = new Zend_Config_Xml(APPLICATION_PATH .'/configs/navigation.xml', 'nav');
my fault. And finally a miss in the navigation.xml file, inside the - node, there should be nodes surrounding each of the "page" nodes, that is for instance for the home. It should have
<configdata>
<nav>
<home>
<label>Home</label>
<controller>index</controller>
<action>index</action>
</home>
That was it !
Again, thanks a lot for your hints and tips i the right direction.
Sinc Kalle Johansson
I think your code is correct, just your protected function __initNavigation()
should use just one _ in your _initNavigation()
Then change __initNavigation() to _initNavigation()