I'm pretty new to php and Zend in general, so I'll try to be as clear as I can. I have taken over a complete web project written in PHP.
In the main layout is script partials/menu.phtml, where is a list of few pages. And I wanted to add another one (called pricelist). I created a new pricelist.phtml file in directory info/ with other pages leading from this menu (in view).
Then in InfoController I created new public function pricelistAction() which includes
$this->view->headTitle()->append('Info');
$this->view->headTitle()->append('Pricelist');
Nothing is written in model. When I run localhost and click Info - Pricelist, the page is not found. I have no clue what I might have forgotten or what is wrong. I'm stuck on this for several days and starting to be desperate. I really appreciate any help. Thank you very much!
Two things:
Make sure there is a proper route in your module.config file that causes this action to be triggered. /baseroute/:action or /baseroute/pricelist...something like that
There are several ways of loading views/templates: Some developers require you to set new view files up explicitly in the view_manage=>template_map section of your module.config file, rather than let zend handle it automatically.
It's hard to guess without seeing your code/directory structure but this is where I would start.
Related
I'm kind of new to Prestashop and I decided to practice on a project that's completed already (Prestashop 1.6.1.18). The thing is the project is pretty large and sometimes I get lost in the folder structure. I come from Codeigniter and Symfony and thought that might have been useful thinking Prestashop too had a similar URL->Controller->View mechanics but so far I've been going on for a while now trying to find the controller (and controller function) which handles this specific URL:
http://localhost/content/discount-products
I would appreciate some insight on how URL end points make their way to a function in a controller. Are they registered somewhere (Routes.php in Codeigniter, config files in Symfony). Should I be able to now this from that URL alone?
Thanx
Use this code on hookDisplayHeader
p($this->context->controller);
This code gives you all information about current controller on both BO and FO
I googled alot and couldn't come up with an answer...
I'm using the tutorial-skeleton application. It automatically includes under 'view/album/album' the html files corresponding to my actions like add or index.
I'm using a submodule and the standard loading won't find my html-files. I followed this guide for setting a custom template path. This works for the index because here I use a ViewModel instance.
But my add/delete/edit actions just return an array like this one.
Is there a way to tell Zend that it should use a different directory to look for the views?
PS: I also tried this injectTemplate approach but no luck. It just sets the Controller namespace/path which is ok in my case.
This was an project specific issue...
I used MasterData as top namespace. When creating the directory tree in my module\MasterData\view I wrote masterdata instead of master-data. This caused the not finding of my views.
A dumb one... I know.
As I said in a different post, I'm trying to adapt an open source intranet to my needs. One of the things I'm trying to do is make the intranet look for the view templates in a different folder than the default ($customViewPath and $defaultViewPath, from now on).
I'm totally unexperienced with Zend Framework and I'm having a hard time figuring some things out, but with this one I think I have come to a dead end.
What I'm trying is to add my custom path for the view templates by using $view->addScriptPath($customViewPath) in the bootstrap. Actually, it works, but only if the view file doesn't exist in $defaultViewPath. What I want is just the opposite: if a custom file doesn't exist in $customViewPath, load the default view from $defaultViewPath.
If I print getScriptPaths(), I get array($defaultViewPath, $customViewPath). That is, somewhere in the life cycle of the script, $defaultViewPath is added to the list of view paths with a higher priority than my custom path. I can't find where this happens, and don't think it is in every module controller.
Also, I know I must move my piece of code $view->addScriptPath($customViewPath) somewhere outside the bootstrap, since the custom path is module related, but I can't access the module name from my bootstrap because request hasn't been initiated yet. I guess I could change that, but I would like to keep the original behaviour as much as possible.
I have read every bit of info about addScriptPath(), setScriptPath(), getScriptPaths() I could understand, but still have no idea on how to apply that to my case. Any idea will be welcome.
I'm aware I should provide more information about the application, but my lack of experience makes me not know what else can be necessary. Please feel free to ask for anything that could make my problem clearer.
The code of the application can be downloaded from its web. I just don't post the link here so that it doesn't look like spam.
Edit:
I'm sorry to insist on this topic, but the more I learn about ZF the more puzzled I am with the issue.
I have traced the stack of view paths, and somewhere between my plugin preDispatch() and the action preDispatch() functions, the default path (the one I'm trying to override) is pushed into the stack.
The only thing I can think of is some other plugin is being executed after mine. I have tried to give my plugin a very high execution order number, but still nothing.
I'm not exaggerating if I say that I have spent at least two weeks on this issue (tho I can't afford to spend more time on this at work, I am spendin a lot at home), I have read everything I could put my hands on about the dispatch cycle, but I don't know what to try next.
Just in case I may be right, is there any way to list from an action what plugins are being executed and their order?
Basically you have reverse the order of the path stack.
Try:
protected function _initView()
{
//Initialize view
$view = new Zend_View();
//reset script path stack with custom view path
$view->setScriptPath($customViewPath);
//add default path back to path stack
$view->addScriptPath($defaultViewPath);
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
'ViewRenderer');
$viewRenderer->setView($view);
//Return it, so that it can be stored by the bootstrap
return $view;
}
this should accomplish pretty much what you are looking for.
I am trying to use the MVC architecture of sugarcrm to add a new action and with that a new view.
I have managed to create a controller with the action and also a class view, the only thing I can't figure out is how to create a simple html page.
Do I really have to use the metada way of sugarcrm?? I just want a simple form with two or three fields.
Are there alternatives to the metadata or do I really have to use it to create my simple page????
You will want to stay within the metadata framework to create your new page if possible. However, once you are in the view controllers, you can echo out anything you wish and still stay "upgrade safe" by overriding the display() function. But, the right way to do what you are wanting to accomplish above is to not only override the display() function but also create a new tpl file (custom/modules//tpls/view.tpl) and then perform whatever you need to perform PHP wise and then assign the variables via the smarty templating engine (I know this sounds complicated - but it's not. It's actually pretty straightforward once you understand Smarty).
One other thing - make sure you are doing all of this (including your controllers and view files) in the custom/modules directory. As this will also keep things upgrade safe. And keep you free from all kinds of headaches in the future. :)
Here is a link to the SugarCRM Developer's Guide online and also a link to their Developer's website. SugarCRM has a pretty good community of developers on the forums so feel free to ask questions there as well.
Developer's Guide:
http://developers.sugarcrm.com/docs/OS/5.2/-docs-Developer_Guides-Developer_Guide_5.2-toc.html
Developer's Site:
http://developers.sugarcrm.com/
Hope this all helps!
Try to do following:
create a new module
put your page into custom/modules/
using URL index.php?module=&action= (without php extension, of course) you can access to your page.
If you'd like to have different action name and page name then you should add the file action_file_map.php
into your module directory and specify inside the mapping:
$action_file_map['action_name'] = 'path_to_your_page';
Note that action_name must be all lowercase - the SugarController won't be able to to match mixed-case actions (true as of SugarCRM 6.1.2).
We have taken on a site written in Zend framework. We didn't write the site and haven't use the Zend framework before so I'm interested in finding three things.
How do I add new views to the site, adding in a new folder to the application/views/scripts directory seems to do nothing
Are there any tutorials on how to add affiliate feeds and setups to a zend site that you can recomend?
Are there any good tutorials on learning the framework? So far all I've found is vast amounts of material that confuses me
to answer your questions in order:
You have to find the controller, that will emerge the view you want to add. There are two ways to get a view script rendered. The first one is a naming convention on the view script. The view has to be the same name as the action name of the controller. Like "indexAction" and index.phtml. The other way is to instanciate a view object within the controller and give a string with the view name at runtime. You may want to look at this excerpt:
$view = new Zend_View();
$view->a = "Hay";
$view->b = "Bee";
$view->c = "Sea";
echo $view->render('someView.php');
which I took from http://framework.zend.com/manual/en/zend.view.controllers.html#zend.view.controllers.render
I don't think that I understand what you mean by "affiliate feed"... are you talking about advertising or is it more like content syndication?
The first thing you should read may be the Zend Framework Study Guide which you find here: http://www.zend.com/community/downloads. There are many tutorials an howtos out there but, this guide is made from Zend directly and should cover the main topics.
Regards,
Mario
Are you adding the appropriate Zend_Controller as well? The Zend_Controller QuickStart is a good place to get started with MVC.
You might also look at Zend_Tool, which provides a script to help create the necessary structure.
Basically, views need corresponding controller actions. So the main index action (located, for example, in application/controllers/IndexController.php) would need a corresponding view at /application/views/scripts/index/index.phtml.
example: To reach an action within the Index Controller named fooAction() you would need a view file at /application/views/scripts/index/foo.phtml.
example: To reach the index action of contact controller you would need the controller at /application/controllers/ContactController.php (with an indexAction() inside it) and the view at /application/views/scripts/contact/index.phtml.
Getting beyond the absolute basics... view rendering can also be turned off or redirected but that is getting beyond the basics. Also if the app uses Zend_Layout there will be a layout file located somewhere like application/layouts/scripts/layout.phtml
Clear, concise and current ZF info can be strangely hard to come by. For tutorials check out:
The ZF Quickstart
Rob Allen's tutorial
Some screencasts
For adding feeds I suppose you should check out the framework's documentation for Zend_Feed