Setting Page Title - headTitle() - Zend Framework 2 ZF2 - zend-framework

I am currently in the process of building an application with ZF2, everything is going well so far, but I am just having trouble with the page titles (as in the <title> tag in the <head>).
In my layout.phtml I have it statically set a string using $this->headTitle().
I want it to basically include the name of the module, controller and action by default, just like the doc page suggests:
http://framework.zend.com/manual/2.1/en/modules/zend.view.helpers.head-title.html
However when I try and implement the example code, I get an Exception.
Frankly the documentation should at least show you the best place to put this code.
I am looking for an example that a ZF2 noob can follow. I basically want to place some code somewhere (presumably Application\Module.php) so that I can set the default title as "Module - Controller - Action", then I need an example of how to override it easily from each controller or view (whichever is preferred)... please help! :)

As per Sams comment...
Readthedocs has the working example: http://zf2.readthedocs.org/en/latest/modules/zend.view.helpers.html#headtitle-helper
Thanks for your help Sam!

Related

Add Route to ajax Link?

I am still very new to Zend Framework and work on my first small Project. I have now come across from Routing, which is a great tool. Unfortunately I do not get it to run on my Ajax Link. I also can't find any information about it. Is there a way to add routes to an Ajax Link? Thank you very much in advance for any hint. Below is my try, but no sucess.
echo $this->ajaxLink("Remove",array('article' =>$this->escape($entry->id),'deleteB',true),
your ajax link should point just as normal link to the action in your controller. The only thing you need to do is disable rendering view which is by adding:
// path/ExampleController.php
public function removeAction()
{
// Disable layout
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
// Your code to remove goes below
}
In my opinion ajax does not need special route. Hope that helps somehow
In the docs there doesn't seem to be any info on passing a route name as a parameter, at least I cannot find any - I'd be happy to be proven wrong.
I guess you can work around this problem for now, constructing the $url with the url() view helper and passing it then to the ajaxLink helper. Check out the ZF documentation page to make sure you pass the right parameters in the right places.

How can I use the Inversion of Control concept in Sitecore to get non-page items to display themselves?

I have a number of non-page content items that are used as "callouts" on the side of pages throughout my website that I am building in Sitecore. Ideally I would like to be able to define the presentation information for these callouts independently. Then when a CMS author selects callouts for a particular page in the site, they know how to display themselves. I read an excellent blog post about how to do this here: http://www.awareweb.com/AwareBlog/InversionControl2.aspx. I used the first method that he describes in the post.
However my implementation of that code doesn't completely work. It seems to get the correct rendering and it iterates properly through the selected non-page callout items. But when it displays them on the page it seems like the callout items are still using Sitecore.Context.Item as their source item and not the source item that was passed in to them via the strDataSource variable as seen in the example code.
Do I have to do anything special in the code behind for the sublayouts for the callouts to tell them not to use Sitecore.Context.Item and instead to use the source item that was passed in? Otherwise I can't figure out why it's not working. Any ideas?
Thanks,
Corey
Setting the DataSource in a sublayout doesn't explicitly set the Context.Item to a different value, it just sets a property in a sublayout that it can use itself.
Rather than write up the solution again, John West's blog already covers this subject here, so I'd recommend you read that - http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/How-to-Apply-Data-Sources-to-Sitecore-ASPNET-Presentation-Components.aspx
I would recommend using the SublayoutParameterHelper Shared Source library which provides a Helper and a base class to use with your sublayouts for accessing the Item represented by an ID set in the DataSource; John also cites this library in his blog post.

Sub-pages in zend framework

it's probably obvious because i didn't find anyone who talk's about it:
there is module/controller/action - but what if the website depth is much deeper
?
for example:
module/controller/action/sub-page(s)/sub-sub-page(s)/and so on..
is routes is the correct way for it?:
puting the action for the module/controller/action/sub-page in the controller and making a route for it.
Am i missing something or this is the way to do it?
The Sub-page is a actually not a Sub-page but still rendered by an view script that refers to an controller/action.
Your logic would mean that after the view script is again a controller/action but this is not correct and would violate MVC structure.
Read Zend Framework & MVC Introduction.

MVC Convention over Configuration

I'm building a .NET MVC application. This is mobile web and i cannot use jQuery.
In my application every process is a 3 step action witch leads me to a 3 aspx per process.
My processes can be categorized so i'd like to code my controllers like: ProcessTypeAController, ProcessTypeBController.
My Views should be like: \ProcessTypeA\Process1\1.aspx, \Views\ProcessTypeA\Process1\2.aspx and \Views\ProcessTypeA\Process1\3.aspx.
By convention this not work because the Controllers dont have the same "location" than Views.
Please Help in this question!
Thank U ALL.
You could specify the location of a view:
return View("~/Views/ProcessTypeA/Process1/1.aspx");
As an alternative you could write a custom view engine in order to modify the default view location conventions. Scott Hanselman wrote an excellent blog post about how this could be achieved.

How should I use <a href> tag to access other templates in lift?

According the Lift wiki, I know the "View First" concept of Lift. That's very different from any framework I used. Take the basic JSP things as the example, I could write
Create a new post
in the page, and write the logic in a servlet. How can I do things like this with lift? I wrote the same tag in a template and when I accessed this page I got 404 error. But if I add a Menu to the SiteMap, things goes well. Is there any possible to make a link without making a new Menu? I am a beginner of Lift and Scala. Thanks in advance.
When everything is declared in your SiteMap, you can have Lift generate the links for you.
Yes, it is possible.
Just don't call LiftRules.setSiteMap at your boot class, then Lift will let you access every pages under your webapp/ directory. You could test your code in this mode.
But this will also lead to no access control, so be careful.
It is also possible to do what I think you asked, which is to make the link accessible, but not visible in the SiteMap (if you don't want the SiteMap at all, go with Brian's answer), with code like this:
SiteMap(Menu("PreClass") / "preClass" >> Hidden)
We prefer to leave the SiteMap enabled as tightly controlling access seems like a good idea in our case.