url for an action of a controller in zend framework - zend-framework

I am trying to learning Zend framework. For that I have installed NetBeans IDE and download zend framework's library. I have created one small application by NetBeans IDE and place the zend framework's library under library folder.
Under Controller folder, in IndexController.php file, I have written one action called indexAction() and there I write simply $this->view->assign('title', 'Hello, World!');.
Under views/scripts/index folder create one file called index.phtml and there I have written out <h1><?php echo $this->escape($this->title); ?></h1>.
My main folder name is phpproject1 and under that I have created all other folders like application, library,public.
Now please suggest me how to open that action in browser?
e.g. - In codeigniter it is like : localhost://project_name/index.php/controller_name/action_name
Thanks in advance.

I assume your installation is correct and you didn't configure any route. try to adapte this to your case.
http://lcalhost/[project_Name]/public/[Module_name]/[Controller_name]/[action_name]
in case you dont have Module;
http://lcalhost/[project_Name]/public/[Controller_name]/[action_name]

Related

Loading module outside zend framework

I am using ZEND 3 and I need to use a module in ordinary PHP file outside framework. How can it be done - make instance of the module and call some method, please?

Zend Framework 1.11: how to autoload a class that uses namespaces

I have a Zend Framework 1.11 application, and I want to use a package called RandomLib. The problem is, it doesn't have an autoloader, and I've tried reading the Zend documentation on using autoloaders, but I can't make sense of it.
I've placed the RandomLib folder in my library directory. What kind of code would I need in my Bootstrap.php file to autoload the class?
Starting in version 1.10.0, Zend Framework now allows loading classes from PHP namespaces. This support follows the same guidelines and implementation as that found in the ยป PHP Framework Interop Group PSR-0 reference implementation. Source
Put content of RandomLib/lib under library/RandomLib
In application.ini add autoloaderNamespaces[] = "RandomLib"
If you wish you can include namespace libraries directly in your Bootstrap.php file after you moved the library in "library/MyExternalLib"
protected function _initAutoLoader()
{
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyExternalLib');
return $loader;
}

Zend/Controller/Action.php file missing

I'm new to Zend framework, and was trying out the Guestbook tutorial that Zend has on it's web site. I have the latest framework downloaded and setup properly; php.ini include_files has the library location set correctly. In the Guestbook tutorial, the GuestbookController extends Zend_Controller_Action and that's what I typed, but I keep getting error stating that Zend_Controller_Action is not found. Turns out, the folder Controller is missing from /library/Zend. I tried re-downloading Zend Framework thinking I might have accidentally deleted it, but it's not in the newly downloaded framework directory either. So, where can I get the Controller folder that contains all the required class files? Or how can I fix the issue? Any help is much appreciated.
Thanks
Kuni
It sounds like the tutorial you are following is for ZF1. ZF2 was released last year and works quite differently. You might want to try the quickstart from the current manual instead:
http://framework.zend.com/manual/2.0/en/user-guide/overview.html
Alternatively you can still download version 1.12 from the Zend site.

How to make Modules use Application View Helpers?

Since, adding some extra modules to the zend framework application, a lot of errors are popping out. By default, all the extra modules tend to use the same layout file to render a html, but for view helpes, it searches it's own folder.
In my case, I made a view helper, to load some template's css file. I named it LoadTemplate and placed it inside APPLICATION_PATH."/view/helpers"
It works perfectly, until I browse to a module. Then it gives a error saying
Plugin by name 'LoadTemplate' was not found in the registry; used paths: Custom_View_Helper_: x/x/application/modules/custom/views\helpers/ Zend_View_Helper_: Zend/View/Helper/
It is searching in the wrong folder.
Can't we tell it to search its folder first, and if not found go and find the helper from the default or Application's View Helper?
If your helper is in that directory, make sure it is called Zend_View_Helper_LoadTemplate, the function is called loadTemplate and the file name is LoadTemplate.php
Edit -
Also check out this blog post by Rob Allen: http://akrabat.com/zend-framework/view-helpers-in-modules/

how to load models from another module in zend framework?

i am developing an application using zend framework.
i have two modules, admin and default, and each of them has their specific model directory.
i want to know, if i can instantiate a model in admin module from within default module and if this approach has problem regarding to the MVC model.
thx in advance.
So long as youve set up the Zend_Application_Resource_Modules or something pretty equivalent all you models should be registerd with the autoloader via the Zend_Application_Module_Autoloader that the modules resources registers. In short, if you follow the default way of doing things, then Models from all modules will be set up for Autoloading in the bootstrap phase.
About Zend Application and Resources
You can call get_class(): http://us3.php.net/get_class
There's possibly a more zend like way to do it, but I don't know. Check the docs.
What about call via object?
Like inter-connect two model functions in controller.
$contacts = new Model_DbTable_Contactsmdl(); // Model file in contact module
$update_id = $contacts->updateContacts($cn_id', $responsearray);
This code inside my syncController.
So you can handle admin / model function in default / controller.